Mysql_fetch_array () problem while ($ row = mysql_fetch_array ($ result ))
{
Echo $ row [0];
}
Why can I output the queried data one by one, but it cannot be put into the for loop, as shown in the following figure:
For ($ I = 0; I I <366; $ I ++)
{
Echo $ row [0];
}
In this way, data cannot be output correctly!
If I want to put the data queried from the database into the for loop, like the odbc_fetch_into ($ result, $ row) function, I want to put the data results in the array, use the following table of the array to operate the dataset. Please kindly advise.
Reply to discussion (solution)
Writability with a for loop
for($i=0; $row=mysql_fetch_array($result); $i++) { echo $row[0];}
While ($ row = mysql_fetch_array ($ result ))
{
Array_push ($ array, $ row [0]);
}
Var_dump ($ array );
Writability with a for loop
for($i=0; $row=mysql_fetch_array($result); $i++) { echo $row[0];}
This is an endless loop.
Why is it an endless loop?
There seems to be more than one field in your database, but you actually have only one echo $ row [0.
Writability with a for loop
for($i=0; $row=mysql_fetch_array($result); $i++) { echo $row[0];}
While ($ row = mysql_fetch_array ($ result ))
{
Array_push ($ array, $ row [0]);
}
Var_dump ($ array );
Learned
I still don't know the difference between for and while.