Hi everyone and thanks for reading. This problems been driving me nuts for the last day and I'm completely stuck. I made a dummy table of users to test out SQL connections but everytime I echo out the information, it keeps dropping the first record, and jumps straight to record two onwards. If I sort the query using ORDER BY 'id' desc, then it will drop the last record and start on the one before the last; any ideas whats gone wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP: Alternate Table Row Colours</title>
</head>

<body>
<?
  $connection = mysql_connect("mysql.thepianoman.info", "****", "*****");
  $database_select = mysql_select_db("mytests", $connection);
  $result = mysql_query("SELECT * FROM members", $connection);
  $row = mysql_fetch_array($result);

  while ($row = mysql_fetch_array($result)) {
      echo $row["id"];
      echo $row["firstname"];
      echo $row["lastname"];
      echo $row["username"];
      echo $row["password"];
      echo $row["email"];
  }
?>
</body>
</html>
<?
  mysql_close($connection);
?>

Thanks,

Anthony

just delete out the

"$row = mysql_fetch_array($result);"

and it would be fine.

Your 100% right, that worked. I'm totally confused now because I'm almost positive that I've had queries work properly with that command before. Can you elaborate on why this happened and why taking that line out fixed it?

Thank you very much,


Anthony

it is because that $row is supposed to be 0 in the opening of the while loop which will get row 0 or the first row in the result.If you set the $row into the mysql_fetch_array,the result will not be zero instead its 1 so you always get row 1 or the second row.Happy coding friend!

it is because that $row is supposed to be 0 in the opening of the while loop which will get row 0 or the first row in the result.If you set the $row into the mysql_fetch_array,the result will not be zero instead its 1 so you always get row 1 or the second row.Happy coding friend!

I understand now; by using mysql_fetch_array it's bringing the pointer forward, so that the while loop is missing the first record (because I had two mysql_fetch_array's!)

Thank you for explaining that.

Anthony

Well for me locally this works but online first loop is still not working. its still the same :S what can be the problem?

This question has already been answered. Start a new discussion instead.