How do I list data from a specific database table as a list with links?

Purag picture Purag · Jul 31, 2011 · Viewed 7.8k times · Source

I'm working on my own simple Content Management System to implement on my projects for clients who want to do their own maintenance.

I'm going to contain only page titles and their content in a database table. All I want is to make a list which takes all the page titles and puts them into a <ul>. I believe I should use foreach, but I'm not too good at PHP, so I'd appreciate some help.

So how would I go about this?

Answer

Quasdunk picture Quasdunk · Jul 31, 2011
<?php
  $qry = mysql_query("SELECT * FROM links");
?>
<ul>
<?php while($row = mysql_fetch_array($qry)) { ?>
  <li><a href="<?php echo $row['link_url']; ?>"><?php echo $row['link_title']; ?></a></li>
<?php } ?>
</ul>

...in case your table with links has the colums 'link_url' and 'link_title'. But you get the idea, I guess.