| | |
MySQL While Loop Won't Show First Row
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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?
Thanks,
Anthony
PHP Syntax (Toggle Plain Text)
<!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
Last edited by antwan1986; May 29th, 2008 at 8:38 pm.
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
•
•
•
•
just delete out the
"$row = mysql_fetch_array($result);"
and it would be fine.
Thank you very much,
Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
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!
Thank you for explaining that.
Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
![]() |
Similar Threads
- Help me with my myspace clone (PHP)
- send data from while loop to mysql database (PHP)
- help in mysql (PHP)
- Data from mysql in a 3 columns table (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Loading a page on opening of a pop-up????
- Next Thread: help--I want to edit article position in joomla
| Thread Tools | Search this Thread |
ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail mediawiki menu mlm multiple mycodeisbad mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search seo server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign websphere white xml youtube





