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: