SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why is one row missing

    hi there,

    to show some of the database data, i use the following script:
    PHP Code:
    $result mysql_query("SELECT * FROM users where name='$name' and joined='$date'") or die(mysql_error());  
    $row mysql_fetch_array$result );
    $total mysql_num_rows($result); 
    while(
    $row mysql_fetch_array($result)) 
    {
    echo 
    $row['name'];
    echo 
    $row['joined'];
    echo 
    "<br>"

    the problem is it when $total = 10 (for example), it can only echo out 9 rows, the first row is missing.

    any idea why?
    thanks

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I think it's because you are assigning 2 result handlers to the query....
    PHP Code:
    $result mysql_query("SELECT * FROM users where name='$name' and joined='$date'") or die(mysql_error());   
    $total mysql_num_rows($result); 
    while(
    $row mysql_fetch_array($result)) 

    echo 
    $row['name']; 
    echo 
    $row['joined']; 
    echo 
    "<br>" 

    Should work
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    more like you were fetching the first row without printing it

    Code:
    $result = mysql_query("SELECT * FROM users where name='$name' and joined='$date'") or die(mysql_error());  
    $row = mysql_fetch_array( $result ); <-- HERE 
    $total = mysql_num_rows($result);
    while($row = mysql_fetch_array($result))
    {
    echo $row['name'];
    echo $row['joined'];
    echo "<br>"
    }
    David

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    which in esscence assigns 2 handlers to one result......
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys!

    you both are right!

    the code spikeZ modified worked. Cheers!

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    no worries
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •