PHP查询从table2获取记录到表1

I got 2 tables

student

S_ID, LastName, FirstName, MiddleName

takensubject

S_ID, SubjectCode, Time

I have a code below using session to display who take the Subject from takensubject but it only display ID what I want is to display the full name of a student using ID from takensubject my code below show some error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean. can anyone help me to correct my query?

<?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);
?>

It keep showing this Warning:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean

</div>

I don't see the columns SchoolYear,Semester in your any of the table.. also you need to specify the table beside the column name like so tb2.Time. Also echo your query and try it in phpmyadmin directly to check the error. Hope it helps :) try something like

SELECT takensubject.*,student.* FROM takensubject INNER JOIN student ON takensubject.S_ID=student.S_ID where takensubject.SchoolYear ='$Sy' and takensubject.Semester ='$Sem' and takensubject.SubjectCode='$sescode' and takensubject.Time='$sestime'

I guess your query is returning FALSE. Try something like this.

SELECT tb1.*, tb2.*
   FROM takensubject tb2
   INNER JOIN student tb1
   ON tb1.S_ID= tb2.S_ID
   WHERE SchoolYear ='$Sy' 
   and Semester ='$Sem' 
   and SubjectCode='$sescode' and Time='$sestime';