Check_user_login (); Check whether the user is logged in $db->createcon (); Establish a connection//$user =$_session["user"]; $user = "Libero"; The test temporarily uses//executes the User data table to select the user data $sql_user = "SELECT * from user where user = ' $user '"; $user _array = $db->fetch_array ($ Sql_user);//Perform yytable data acquisition yytable all data $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 gets 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))
First consider $sql_yytable this SQL statement is wrong at this time will return "data query failed"
The while statement is a pay-value expression and is always true
Print out the SQL statement $sql_yytable = "SELECT * from yytable where uid = ' $user _array[0] '"; Then go to the database and perform the following to see the results
Get $sql result set based on query criteria
Public Function Fetch_array ($sql) {
if ($result = $this->query ($sql)) {//use while after this judgment has been established so it becomes a dead loop $rs = Mysql_fetch_array ($result, Mysql_both);
return $rs;
} else {
echo "Data query failed";
}
}
while ($yytable _array = $db->fetch_array ($sql _yytable)) {
Always executes the query $db->fetch_array ($sql _yytable) and always returns the first result
Your Fetch_array method can only be used to query a record of the occasion
You should write another Fetch_all method, query and return all results
while ($yytable _array = $db->fetch_array ($sql _yytable)) {
Always executes the query $db->fetch_array ($sql _yytable) and always returns the first result
Your Fetch_array method can only be used to query a record of the occasion
You should write another Fetch_all method, query and return all results great God, you're right. I have been only looping through the first statement, if you want to loop out all the other results, specifically, please express
Get $sql result set based on query criteria
Public Function Fetch_array ($sql) {
if ($result = $this->query ($sql)) {//use while after this judgment has been established so it becomes a dead loop $rs = Mysql_fetch_array ($result, Mysql_both);
return $rs;
} else {
echo "Data query failed";
}
} know where the problem is, the key is how to solve ah I want to output all the results that meet the query criteria
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 return is an array, you have to follow the array to do the work