Will Evans Will Evans - 2 years ago 79
SQL Question

How to display MySQL data in a list

I will be using data from a MySQL database and to receive that data I will be using this code:

SELECT link, notes FROM links WHERE useri_id=XXX;

I am now stuck on how to display this nicely in a list where it will be a link and then on next line the notes for that link and then a spacer line and then it will display the next link and notes and so on. How would I code this?

Answer Source

You can use something like this:

$rs = mysql_query("SELECT link, notes FROM links WHERE useri_id=XXX") or die(mysql_error());

echo "<ul>";
while( false !== ($row = mysql_fetch_assoc($rs)))
  echo "<li>";
  echo "<a href='" . $row['link'] . "'>" . $row['link'] . "</a><br />";
  echo $row['notes'] . "<hr />";
  echo "</li>";
echo "</ul>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download