Will Evans Will Evans - 6 months ago 22
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

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>";
Comments