Page 1 of 1

PHP Noob here - trouble displaying last value in an array

Posted: Mon Sep 27, 2010 2:16 pm
by molossus
Hey, as I said, I am working on my very first project in php. So far so good! However, there is something I can't get past. I am sure it's simple, I am just missing it.

The problem is that, while my data fills out the table very nicely, it does not include the last row. If there are 3 entries, it will only show 4, etc.

Here's my code:

Code: Select all

$row = mysql_fetch_array($result);
$rowcolor = 1;

while($row = mysql_fetch_array($result))
{
    if ( $rowcolor==2 ) { echo "<tr class='rowColorDark'><td>"; $rowcolor = 0; } else { echo "<tr class='rowColorLight'><td>"; }
    echo $row['distroname'] . "</td><td>" . $row['logins'] . "</td><td>" . $row['lastlogin'] . "</td><td>" . $row['username'] . "</td><td>" . $row['password'] . "</td></tr>";
    $rowcolor++;
} 
I'm a little, tiny baby.

Re: PHP Noob here - trouble displaying last value in an arra

Posted: Mon Sep 27, 2010 2:19 pm
by jabbaonthedais
You mean if there are 4 entries it only shows 3? You said that backwards. There could be something in your query excluding the extra row. Have you tried running the query in phpmyadmin to see if it brings back all the rows?

Re: PHP Noob here - trouble displaying last value in an arra

Posted: Mon Sep 27, 2010 2:51 pm
by AbraCadaver
Because you do mysql_fetch_array() for the first row and you don't do anything with it. Then you start your loop and it starts at the second record. Get rid of the:

Code: Select all

$row = mysql_fetch_array($result);