Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation basic sql help please!!

    Hi All,

    i need some basic help please,

    i am having trouble getting a list of info from a specific row in my database, i have checked the number of rows which returns the correct number but when i print out my results i am getting the first record print out 47 times instead of each of the 47 records printing out once.

    where am i going wrong with this?

    PHP Code:
    $sql "SELECT *
            FROM rss_feeds
            WHERE description = 'top'"
    ;
    $query mysql_query($sql);
    $row mysql_fetch_array($query);
    $rows mysql_num_rows($query);

        for (
    $i 0$i $rows$i++) {
    $feedURL[$i] = $row['s_FeedURL'];
    print 
    $feedURL[$i];
    print 
    "<br />";

    cheers

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    your question is likely not to do with sql but your php code. run your query directly in mysql client and see if it gives you correct rows. if it does you've just verified the problem is your output code.

    take a look in the php manual to make sure you are looping correctly.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok thanks mate,

    just checked the sql and its displaying the correct records,

    i will check the php manual to see if that helps

    cheers

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    How about using while instead of for?

    PHP Code:
    $sql "SELECT * 
            FROM rss_feeds 
            WHERE description = 'top'"

    $query mysql_query($sql); 
    $row mysql_fetch_array($query); 
    $rows mysql_num_rows($query); 

        while (
    $i 0$i $rows$i++) { 
    $feedURL[$i] = $row['s_FeedURL']; 
    print 
    $feedURL[$i]; 
    print 
    "<br />"


  • Users who have thanked Hayyel for this post:

    LJackson (04-06-2009)


  •  

    Posting Permissions

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