mysql - PHP query fetching records from table2 to table 1 -
i got 2 tables
student
s_id, lastname, firstname, middlename
takensubject
s_id, subjectcode, time
i have code below using session display take subject takensubject display id want display full name of student using id takensubject code below show error warning: mysqli_num_rows() expects parameter 1 mysqli_result, boolean. can me correct 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 * takensubject tb2, student tb1 tb2.s_id=tb1.s_id , schoolyear ='$sy' , semester ='$sem' , subjectcode='$sescode' , 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 warning:
mysqli_num_rows() expects parameter 1 mysqli_result, boolean
i guess query returning false
. try this.
select tb1.*, tb2.* takensubject tb2 inner join student tb1 on tb1.s_id= tb2.s_id schoolyear ='$sy' , semester ='$sem' , subjectcode='$sescode' , time='$sestime';
Comments
Post a Comment