Foreach returns only partial results, While works...
Posted: Fri Jun 25, 2004 8:22 am
I need to select rows from database table "filenames" and then display them.
The below code works just fine:
But this code behaves real strange:
There are currently 20 rows and the first code which uses "while" does display all of them properly. The second piece of code which uses "foreach" does display only 8 rows starting with the second one.
Any ideas what the problem could be? Of course I can simply use the code that works but I would like to know why the other code behaves so odd.
Thanks!
Tomas
The below code works just fine:
Code: Select all
$query = "SELECT * FROM filenames";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$orig_name = $row["orig_name"];
$new_name = $row["new_name"];
echo "$orig_name<br>";
}Code: Select all
$query = "SELECT * FROM filenames";
$result = mysql_query($query);
foreach(mysql_fetch_array($result) AS $key => $value){
$row = mysql_fetch_array($result);
$orig_name = $row["orig_name"];
$new_name = $row["new_name"];
echo "$orig_name<br>";
}Any ideas what the problem could be? Of course I can simply use the code that works but I would like to know why the other code behaves so odd.
Thanks!
Tomas