php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26234 While Loops
Submitted: 2003-11-13 00:34 UTC Modified: 2003-11-13 00:37 UTC
From: spock1985 at homail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.4 OS: Win Xp
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: spock1985 at homail dot com
New email:
PHP Version: OS:

 

 [2003-11-13 00:34 UTC] spock1985 at homail dot com
Description:
------------
When using a while loop such as in the example below:


It skips over the very first entry within the table. 
Say I have 5 rows which have a lvl of 3, when printing out the name of said row, only the last 4 will print out.

Reproduce code:
---------------
mysql_connect (localhost, root, '');
mysql_select_db (Arakaron);
$result=mysql_query ("SELECT * FROM magic WHERE lvl='3'");
$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result))
{
print $row['name'];
}

Expected result:
----------------
I expect to see all 5 names of the rows instead of the last 4.

Actual result:
--------------
Only shows the very last 4 rows which have a level of 3.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-13 00:37 UTC] gschlossnagle@php.net
your code logic is flawed.  you fetch twice before taking 
any action. drop the first '
$row = mysql_fetch_array($result);' an you should be fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC