What is the difference between the two ways of writing PHP? Solution Ideas

Source: Internet
Author: User
What is the difference between the two ways of writing PHP?
First wording:

$sql = "SELECT * FROM table";

$query =mysql_query ($sql);

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

echo "Output";

}







The second wording:
$sql = "SELECT * FROM table";

$query =mysql_query ($sql);

$row =mysql_fetch_array ($query);

while ($row) {

echo "Output";

}

------Solution--------------------
while ($row =mysql_fetch_array ($query)), see if the value of the $row=mysql_fetch_array ($query) expression is true, if yes, the loop part is executed, and then go back to the previous check $row=mysql The value of _fetch_array ($query) is so looped.
In the second example, $row its value no longer changes, that is, the loop body is never executed, or it is executed forever.
You may need to understand the role of the next Mysql_fetch_array ().
------Solution--------------------
Upstairs positive solution. In addition to Mysql_fetch_array (), this method can also call the Mysql_fetch_object () method to get the results of the SQL query. The specific usage is not to repeat. Baidu a bit above a lot
------Solution--------------------
PHP code
while ($row =mysql_fetch_array ($query)) {//mysql_ Fetch_array A pointer to the internal resource, each call to the downstream data.//Because it is the inlet condition cycle, and then the formation of $row in each judgment is the downlink data, thus can determine whether to reach the end of the data//The second 2 floor said almost. 
------Solution--------------------
2 Floor positive solution, the Mosaic
------Solution--------------------
The difference is: The former is correct, the latter is wrong
----- -Solution--------------------
The first is traversal, and the second is to take the first row, so simple
------solution--------------------
The first one looks like a syntax error (a semicolon in the while expression); the second notation of

looks like a dead loop.


————————————————————————————————
based on the plug-in extension provided by the CSDN forum, I made a signature file tool to share with you, welcome technical exchange:)
------ Solution--------------------
The result of the second kind of loop ... It seems that I have had the experience of the cycle of death. The only way to reboot:
  • Related Article

    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.