1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Little mySQL Problem

Discussion in 'MySQL' started by Pixel T., Nov 19, 2009.

  1. #1
    Hey guys,

    I'm having a little problem. I'm using this code but its only showing me 1 of the rows in the database.

    I would want all of the data to be listed. Not sure why its only one. If I set ORDER BY ASD, it shows 1 piece of data from the last row of the table.

    What am I doing wrong?

    Thanks,
     
    Pixel T., Nov 19, 2009 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Your only fetching data from the query once. You need to loop through it to fetch the rows until you have gotten them all.

    
    $result = mysql_query("SELECT * FROM tournaments WHERE approved='0'");
    
    while ($row = mysql_fetch_array($result)) echo "<br />".$row['name']."<br />";
    
    
    
    PHP:
     
    plog, Nov 19, 2009 IP
  3. Erind

    Erind Peon

    Messages:
    663
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Recommend putting braces after while loop to avoid complications with repeating unwanted lines or not repeating all lines.
     
    Erind, Nov 19, 2009 IP
  4. Pixel T.

    Pixel T. Well-Known Member

    Messages:
    1,205
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    170
    #4
    Ahhh.... I knew I was doing something wrong.

    Thanks :)
     
    Pixel T., Nov 19, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    just noticed that a little optimization is possible in query.
    If approved is a integer column, do not wrap the input with quotes. (Remove quotes around ZERO '0' => 0)

    SELECT * FROM tournaments WHERE approved=0

    What happens otherwise is all the entries in that column will get converted in string type and then compared with '0' which is slower process than integer to integer comparison, though this wont make any difference for small tables but its always good to keep things optimized at early stage itself :)
     
    mastermunj, Nov 19, 2009 IP