Hello guys! I'm wondering how I can list all of my rows from a mysql table in a html-table. I'm pretty sure I have to use a loop but I don't know how. In my mysql table I have two columns: link_name and link_url. I want a to list all of the links with link_name as the name of the link and link_url as the url of the link. I hope someone can help me with this Thanks!
$result = mysql_query("SELECT * FROM table_name"); for($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_array($result); echo '- <a href="' . $row['link_url'] . '">' . $row['link_url'] . '</a><br>'; } PHP: hope it works... but, of course, you need a mysql connection above of these codes.
Calculating on each iteration isn't good practice and may slow down the application. You might as well just use the simple way... <?php $sql = "SELECT Foo FROM Bar"; $result = mysql_query($sql); if ( mysql_num_rows($result) > 0 ) { while ( $row = mysql_fetch_assoc($result) ) { echo('This row contains: '.$row['Foo'].'.<br/>'); } } else { echo('Uhh, no results!'); } PHP: