Displaying more than one result
I am using the While() function in PHP to display multiple results from the db, but only one result gets displayed. I know I have more than one row in my DB because I checked, but it only displays once. Here is the code I use to retrieve the info:
<?php
$first_result = mysql_query (\"SELECT * FROM anime ORDER BY id DESC\");
$first_num_rows = mysql_num_rows ($first_result);
$last_result = mysql_query (\"SELECT * FROM anime WHERE id = $first_num_rows\");
while ($arow = mysql_fetch_array($last_result)) {
$name = $arow[\"name\"];
$year = $arow[\"year\"];
$description = $arow[\"description\"];
$url = $arow[\"url\"];
echo (\"<B><U>Name:</b></u> $name<BR>\");
echo (\"<B><U>Year Released:</b></u> $year<BR>\");
echo (\"<B><U>Description:</b></u> $description<BR>\");
echo (\"<B><U>Location:</b></u> <a href=\\"$url\\">$name</a><BR>\");
}
?>
To see the output go to http://icc.ppnhost.ws/test.php
Thanks, Necrotic
[James Logsdon]
necrotic posted this at 23:30 — 15th May 2002.
He has: 296 posts
Joined: May 2002
One thing I see is that it is displaying the Lowest row in the table. Not the first. So... does that help?
nike_guy_man posted this at 00:03 — 16th May 2002.
They have: 840 posts
Joined: Sep 2000
<?php
$first_result = mysql_query (\"SELECT * FROM anime ORDER BY id DESC\");
$first_num_rows = mysql_num_rows ($first_result);
$last_result = mysql_query (\"SELECT * FROM anime WHERE id = $first_num_rows\");
?>
Necrotic... You are saying to see how many rows are in the table anime and then in picks the last one... remove the WHERE id = $first_num_rows bit... thats whats causing the problem...
Hope this works
necrotic posted this at 00:29 — 16th May 2002.
He has: 296 posts
Joined: May 2002
Well god! I feel like a complete idiot! Thanks... it works like a charm.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.