Beginners have some doubts about while.

Source: Internet
Author: User
A beginner's question about while function dql ($ SQL)
{
$ Res = $ this-> mysqli-> query ($ SQL );
If (! Empty ($ res ))
{

While ($ row = $ res-> fetch_row ())

Return $ row;
$ Res-> free_result ();
} Else
{Return null ;}
}
I don't understand why he only returns one statement? There are many results in the query. if The while clause is true, it returns a statement. Why does it only return the last statement?
$ A = 20;
While ($ a <= 30)
{Echo $;
$ A ++}
?>
What is the difference between the above and $ row? It is not the first time to judge in the output, and then to judge in the output? The output will not be made until the condition is invalid. Why is $ row output only once? The condition of $ row is that $ res has no record, so it does not loop .. Is it true that I understand while?
I have always understood that as long as the while condition is true, a code block will be cycled once. it seems that the code block is output after all loops in $ row?


Reply to discussion (solution)

At least your observations are not very careful.
While ($ row = $ res-> fetch_row ())
Return $ row;
Only the first record is returned, not other

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.