Results 1 to 5 of 5

Thread: Returning only 1 row of results?!?!?!

  1. #1
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Question Returning only 1 row of results?!?!?!

    Hi, My code is as follows:

    PHP Code:
    $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


    Josh
    - Josh

  2. #2
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    have you tried a while statement?
    http://www.insanecombat.com << bored? check out ma game

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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:

    Code:
    $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> 
    
    <BR>
    
    <?php
     }
    Hope this helps.
    Last edited by thetestingsite; 10-21-2007 at 11:14 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    It's actually mysql_fetch_assoc if you want to put names in the array.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    assoc does just names; array does indexes and names (meaning that it would get weird with a foreach loop)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •