note 67064 deleted from function.mysql-fetch-array by nlopess
| From: | nlopess@php.net | Date: | Fri, 02 Jun 2006 21:01:01 +0000 |
| Subject: | note 67064 deleted from function.mysql-fetch-array by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-113013@lists.php.net to get a copy of this message | ||
Note Submitter: wmanguiano at hotmail dot com
----
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.