note 67064 added to function.mysql-fetch-array
| From: | wmanguiano at hotmail dot com | Date: | Fri, 02 Jun 2006 19:45:39 +0000 |
| Subject: | note 67064 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113008@lists.php.net to get a copy of this message | ||
I have found something weird with php & mysql and is if use 2 times the command
mysql_fetch_array with the same recordset into a code for get info from a mysql database. when the
info is printed by a while loop there is lost the first record.
example:
<?php
$ssql="select idusuario,usuario from usuarios";
$res = mysql_query($ssql) or die (mysql_error());
$arr1=mysql_fetch_array($res);
while($ddt=mysql_fetch_array($res)){
echo "usuario" . $ddt[1];
}
?>
in this case the table usuarios have 10 records but the while only prints 9 of them, the first is
lost.
the way i fixed the problem is removing the line $arr1=mysql_fetch_array($res); and then the while
finnaly prints the 10 records.
i dont know if is a bug in php or maybe there is any rule i have missed in the php manual about the
use of mysql_fetch_array.
im using php 5.1.3 in my test server and php 4.4.2 in my web server and mysql 4.1.19, in both cases
happens the same thing.
----
Server IP: 66.163.161.117
Probable Submitter: 201.138.61.16
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- http://master.php.net/note/edit/67064
Del: integrated -- http://master.php.net/note/delete/67064/integrated
Del: useless -- http://master.php.net/note/delete/67064/useless
Del: bad code -- http://master.php.net/note/delete/67064/bad+code
Del: spam -- http://master.php.net/note/delete/67064/spam
Del: non-english -- http://master.php.net/note/delete/67064/non-english
Del: in docs -- http://master.php.net/note/delete/67064/in+docs
Del: other reasons-- http://master.php.net/note/delete/67064
Reject -- http://master.php.net/note/reject/67064
Search -- http://master.php.net/manage/user-notes.php