If you encounter a while loop problem, please advise! The problem is as follows: there is an stu table where all the data should be retrieved and the code is written as follows: the result is as follows: what I cannot understand is that the result of mysql_fetch_assoc ($ rs) must be passed to a variable before a positive solution can be obtained. all results cannot be obtained directly in the while loop. I just learned PHP, let the man laugh at me. the tall man gave me some advice! ---- Questions about the while loop, please advise!
The problem is: there is an stu table that needs to retrieve all the data in it,
The code is as follows:
The result is as follows:
Later, I made the following corrections:
The result is correct:
What I cannot understand is that the result of mysql_fetch_assoc ($ rs) must be passed to a variable before a positive solution can be obtained. all results cannot be obtained directly in the while loop. I just learned PHP, let the man laugh at me. the tall man gave me some advice!
------ Solution --------------------
Mysql_fetch_assoc ($ rs) moves the pointer of the result set ($ rs ).
Therefore, while (mysql_fetch_assoc ($ rs) skips some records, because no one takes over the records.
------ Solution --------------------
You executed mysql_fetch_assoc twice.
------ Solution --------------------
Mysql_fetch_assoc ($ rs );
Reads the current record and moves the record pointer to the next row.
While (mysql_fetch_assoc ($ rs) {// here only read, but no output, and the record pointer is moved to the next record
Print_r (mysql_fetch_assoc ($ rs); // Read and output, record pointer moved to the next record
}
Therefore, records with even numbers of programs executed will be output, while records with odd numbers will be skipped without output.