View Full Version : Returning only 1 row of results?!?!?!

10-21-2007, 07:49 PM
Hi, My code is as follows:

$results = mysql_query("SELECT * FROM stories") or die(mysql_error());

$row = mysql_fetch_array( $results );

echo "<a href=story.php?sID=$row[id]&pID=1><img src=images/small_book.gif border=0><a href=story.php?sID=$row[id]&pID=1><font size=4>$row[story]</font></a><br /><a href=delete.php?id=$row[id]&type=story>Delete</a> | <a href=storyPages.php?sID=$row[id]>Edit Pages</a>";

It should be returning all of the results of that table, but its only returning one? (And I know for sure I have multiple rows of data as when I delete 1, the next row shows up).

ANy help would be greatly appreciated :)


10-21-2007, 08:02 PM
have you tried a while statement?

10-21-2007, 08:11 PM
Yes, you need to have a while statement in there to loop through all of the rows in the database. Something like the following should work for you:

$results = mysql_query("SELECT * FROM stories") or die(mysql_error());

while ($row = mysql_fetch_array($results)) {

<a href=story.php?sID=<?php echo $row['id'];?>&pID=1><img src=images/small_book.gif border=0> <a href=story.php?sID=<?php echo $row['id'];?>&pID=1><font size=4><?php echo $row['story'];?></font></a><br /><a href=delete.php?id=<?php echo $row['id'];?>&type=story>Delete</a> | <a href=storyPages.php?sID=<?php echo $row['id'];?>>Edit Pages</a>



Hope this helps.

10-24-2007, 09:28 AM
It's actually mysql_fetch_assoc if you want to put names in the array.

10-24-2007, 09:32 AM
assoc does just names; array does indexes and names (meaning that it would get weird with a foreach loop)