What are the differences between the two php statements? Solution-php Tutorial

Source: Internet
Author: User
What are the differences between the two php statements? First statement: $ SQL & quot; select * fromtable & quot; $ querymysql_query ($ SQL); while ($ rowmysql_fetch_array ($ query);) {echo & quot; output & quot;}: What are the differences between $ SQL & quot; select * fromtable php?
First writing:

$ SQL = "select * from table ";

$ Query = mysql_query ($ SQL );

While ($ row = mysql_fetch_array ($ query );){

Echo "output ";

}







Second writing:
$ SQL = "select * from table ";

$ Query = mysql_query ($ SQL );

$ Row = mysql_fetch_array ($ query );

While ($ row ){

Echo "output ";

}

------ Solution --------------------
While ($ row = mysql_fetch_array ($ query), check whether the value of the $ row = mysql_fetch_array ($ query) expression is true. If yes, execute the loop part, then return to the front and check the value of $ row = mysql_fetch_array ($ query) in this loop.
In the second example, the value of $ row does not change, that is, it either never executes the loop body or runs forever.
You may need to understand the role of mysql_fetch_array.
------ Solution --------------------
Upstairs. In addition to mysql_fetch_array (); you can also call the mysql_fetch_object () method to obtain the SQL query result. The specific usage will not be described in detail. Baidu has many
------ Solution --------------------
PHP code
While ($ row = mysql_fetch_array ($ query) {// mysql_fetch_array contains a resource locating pointer. each call points to downstream data. // because it is an entry condition loop, then $ row is formed, which is downstream data at each judgment. this can determine whether it has reached the end of the data. // The second floor is similar.
------ Solution --------------------
Solution on the second floor, sprinkling flowers
------ Solution --------------------
The difference is that the former is correct and the latter is wrong.
------ Solution --------------------
The first is traversal, and the second is the first line, which is so simple.
------ Solution --------------------
The first syntax seems to be incorrect (a semicolon is added to the while expression );

The second statement seems like an endless loop.


--------------------------------
Based on the plug-in extension function provided by the CSDN forum, I have made a signing tool and shared it with you. we welcome Technical Exchange :)
------ Solution --------------------
The result of the second loop... It seems that I have had an endless loop .. It can only be restarted ..

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.