How can I display an unordered list(<ul></ul>) with 30 entries from a database? They enteries ned to be the most recent with the 1st one being the newest I kmnow I need to use loops but am getting very confused
Cheers
PS: I have a table called gallery with the following fields id(primary), imgTitle, fileName, author,authorAddress, createDate(date)
Comments
Anyway what you need is something similar to this.
[PHP]
<?php
// An example of listing 30 most recent items first from a database into a list.
$result = mysql_query("SELECT * FROM gallery ORDER BY createDate LIMIT 30");
// Conditional statement to check if any data was returned via the query....
if(mysql_num_rows($result) > 0)
{
// Set the starting ul tag before the main loop.
// I AM NOT SURE WHAT DATA YOU WANT TO DISPLAY SO I WILL JUST
// SHOW THE AUTHOR INFO. I AM SURE YOU CAN FIGURE OUT HOW
// TO CHANGE THIS YOURSELF!!!
echo "<ul>";
while($r = mysql_fetch_array($result))
{
echo "<li>" . $r / "</li>";
}
// Ending ul tag
echo "</ul>";
}
?>
[/PHP]
That's a very basic example for you. Just simply adjust it to suit your own needs.
EDIT: oops I forgot the database connection code. I am sure you already have that figured right?
Thanks for your help though I really appreciate it!
sebastianastill.co.uk - My Portfolio
[PHP]<?php
$result = mysql_query("SELECT id, page, title, author, authorWebsite FROM poetry ORDER BY createDate DESC LIMIT 30");
echo "<UL class='list'>\n";
while (list ($id, $p, $t, $a, $aW) = mysql_fetch_row($result)) {
echo "<li> <a href='poetry/$p' target='_blank'>$t</a> - <a href='$aW' target='_blank'>$a</a></li>\n";
}
echo "</UL>\n"; ?>[/PHP]
Thanks anyway! :cool:
sebastianastill.co.uk - My Portfolio
You can just use SELECT * FROM table_name because the "*" means selecting everything. That way you don't have to type out every field name. And the reason the code I showed before didn't work was because I forgot to include the DESC (descending) statement in the query.
Meh seems like you got it working anyway.
sebastianastill.co.uk - My Portfolio