我寫了下面的查詢:查詢在PHP返回null值或空值
$query1 = "SELECT * FROM session WHERE Id_session IN (SELECT * FROM students_in_session WHERE Username = '$email')";
$res = mysqli_query($conn,$query1);
$query2 ="SELECT * FROM students_in_session WHERE Username='$email'";
$res2 = mysqli_query($conn,$query2);
if (!$res) {
die(mysqli_error($conn));
}else{
while ($row = mysqli_fetch_array($res)) {
print_r($row);
$course = $row['Degree'];
$date = $row['Date'];
$hour = $row['Hour'];
$room = $row['Room'];
}
}
if(!$res2){
die(mysqli_error($conn));
}else{
while ($row = mysqli_fetch_array($res2)) {
print_r($row);
$prof = $row['Professor'];
$assis = $row['Assistent'];
}
}
return "\n\nDegree: ".$course."\n"."Date: ".$date."\n"."Hour: ".$hour."\n"."Room: ".$room."\n"."Prof: ".$prof."\n"."Assistent: ".$assis;
}
目前使用phpMyAdmin和測試查詢返回預期的結果,但是使用在代碼中的變量都是空的查詢。
這些數據庫的表:
會議
|Id_Session|Date|Hour|Room|Degree|
students_in_session
|Id_Session|Code|Name|Surname|Username|Professor|Assistent|
哪個查詢返回結果?第一個或第二個或兩個 – Exprator
你應該連接你的電子郵件變量,因爲PHP不能識別單引號中的變量。 ''SELECT * FROM students_in_session WHERE用戶名='$ email'「;'應該是'」SELECT * FROM students_in_session WHERE用戶名='「。 $電子郵件。 「'」;' – Edwin
phpmyadmin中的所有查詢都返回結果,在我的php代碼中沒有。 – killMSN