I'm currently trying to print the result of joining 2 tables using mysqli. but everytime i try to do it, it only return the result from one table while the table that it's joining doesn't return any result
below is the code that show the data into a table
foreach($db->showdata() as $x) {
if($x['role_id'] == 1 || $x['role_id'] == 2) continue;
$id = $x['user_id'];
echo "<tr>";
echo "<td>" . $x['user_id'] . "</td>";
echo "<td>" . $x['first_name'] ." ". $x['last_name']. "</td>";
echo "<td>" . $x['nilai_tugas'] . "</td>";
echo "<td>" . $x['nilai_uts'] . "</td>";
echo "<td>" . $x['nilai_uas'] . "</td>";
echo "</tr>";
}
while this one is the showdata() function it called
function showdata(){
$data = mysqli_query($this->db, "SELECT * FROM user LEFT OUTER JOIN grade ON(user.user_id = grade.user_id) IS NOT NULL;");
while($d = mysqli_fetch_array($data)){
$hasil[] = $d;
}
return $hasil;
}
The structure of the table is
User: user_id, first_name, last_name and other column that's irrelevant for this part
Grade: user_id, nilai_tugas, nilai_uts, nilai_uas
when I run the code it return
Notice: Undefined index: nilai_tugas Notice: Undefined index: nilai_uts Notice: Undefined index: nilai_uas
which is from the grade table, but the data from the user table do go through and show up in the page. The page result
When I run the query in mysql it does return all the data I requested but it doesn't seem to return the data when in the function.
Thank you in advance.
Edit: I tried to move the select query into the same page and it work, it just don't work when I use return from function(which is mandatory).