What is the problem that the phpwhile loop does not return?
Check_user_login (); // check whether the user has logged on to $ db-> createcon (); // establish a connection // $ user = $ _ SESSION ["user"]; $ user = "libero"; // Test temporary use // run the user data table to select user Data $ SQL _user = "select * from user where user = '$ user '"; $ user_array = $ db-> fetch_array ($ SQL _user ); // execute yytable data to obtain all data in yytable $ SQL _yytable = "select * from yytable where uid = '$ user_array [0]'"; echo"
"; While ($ yytable_array = $ db-> fetch_array ($ SQL _yytable) {echo"
"; Echo"
". $ Yytable_array [0]." | "; Echo"
". $ Yytable_array [1]." | "; Echo"
". $ Yytable_array [2]." | "; Echo"
". $ Yytable_array [3]." | "; Echo"
". $ Yytable_array [4]." | "; Echo"
". $ Yytable_array [5]." | "; Echo"
";} Echo"
"; // Dbclass
Query ($ SQL) {$ rs = mysql_fetch_array ($ result, MYSQL_BOTH); return $ rs ;}else {echo "data query failed ";}} // database query execution statement public function query ($ SQL) {mysql_query ("set names utf8"); return mysql_query ($ SQL );} // loop more result set get array public function loop_query ($ result) {return mysql_fetch_array ($ result);} // close database connection public function close () {return mysql_close () ;}}?>
Reply to discussion (solution)
while($yytable_array = $db->fetch_array($sql_yytable))
When the SQL statement $ SQL _yytable is incorrect, "Data Query failed" is returned"
The while statement is a pay-as-you-go expression, so it is always true.
Print the SQL statement $ SQL _yytable = "select * from yytable where uid = '$ user_array [0]'"; then run the following command in the database to check the result:
// Obtain the $ SQL result set based on the query conditions
Public function fetch_array ($ SQL ){
If ($ result = $ this-> query ($ SQL )) {// After The while clause is used, the result is always an endless loop. $ rs = mysql_fetch_array ($ result, MYSQL_BOTH );
Return $ rs;
} Else {
Echo "data query failed ";
}
}
While ($ yytable_array = $ db-> fetch_array ($ SQL _yytable )){
Always query $ db-> fetch_array ($ SQL _yytable) and always return the first result.
Your fetch_array method can only be used to query a record.
You should write another fetch_all method to query and return all results.
While ($ yytable_array = $ db-> fetch_array ($ SQL _yytable )){
Always query $ db-> fetch_array ($ SQL _yytable) and always return the first result.
Your fetch_array method can only be used to query a record.
You should write another fetch_all method to query and return all results. what you said about me is that only the first statement is cyclically output. if you want to loop all other results, please express
// Obtain the $ SQL result set based on the query conditions
Public function fetch_array ($ SQL ){
If ($ result = $ this-> query ($ SQL )) {// After The while clause is used, the result is always an endless loop. $ rs = mysql_fetch_array ($ result, MYSQL_BOTH );
Return $ rs;
} Else {
Echo "data query failed ";
}
} I know where the problem is. the key is how to solve it. I want to output all results that meet the query conditions.
Public function fetch_all ($ SQL) {if ($ result = $ this-> query ($ SQL) {while ($ r = mysql_fetch_array ($ result, MYSQL_BOTH )) {$ res [] = $ r;} return $ res;} else {echo "data query failed ";}}
Of course, the returned result is an array. you need to follow the array for subsequent work.