Mysql_fetch_array ()

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.