我有2個表PHP查詢獲取記錄從表2至表1
學生
S_ID, LastName, FirstName, MiddleName
takensubject
S_ID, SubjectCode, Time
我有以下使用會話顯示誰碼把主題從takensubject但它只顯示ID我想要的是顯示一個st的全名使用ID從takensubject下面我的代碼下面顯示一些錯誤警告:mysqli_num_rows()期望參數1是mysqli_result,布爾值。 任何人都可以幫助我糾正我的查詢?
<?php
include'database.php';
$sescode = $_SESSION['sessioncode'];
$sestime = $_SESSION['sessiontime'];
$conn = mysqli_connect($server, $dbusername, $dbpassword, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM takensubject tb2, student tb1 where tb2.S_ID=tb1.S_ID and SchoolYear ='$Sy' and Semester ='$Sem' and SubjectCode='$sescode' and Time='$sestime'";
$no = 0;
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$no++;
echo"<td>$no).</td> ";
echo"{$row['S_ID']}";
echo"{$row['LastName']}<br>";
}
} else {
echo "No Record Results";
}
mysqli_close($conn);
?>
它繼續顯示此警告:
mysqli_num_rows()預計參數1被mysqli_result,布爾
參考http://php.net/manual/en/mysqli.error.php期間'mysqli_query()'調用,即檢查錯誤查詢 – Saty
檢查是否存在錯誤將其更改爲'mysqli_query($ conn,$ sql)或死(mysqli_error($ conn));' – mitkosoft