Please help me, how to compare 2 name from different query? I want to compare subject1 with subject2 if its same words it will printing 'YES' (like the image).
So this is my code, my code just read the last query from subject1. So how can I compare all query from subject1 with all subject2?
<table class="table table-bordered">
<tr>
<td class="table-bordered">No</td>
<td class="table-bordered">Date</td>
<td class="table-bordered">Subject Name</td>
<td class="table-bordered">Subject No</td>
<td class="table-bordered">Revision No</td>
<td class="table-bordered">Trainer</td>
<td class="table-bordered">Institution</td>
</tr>
<?php
$query = mysql_query("SELECT * FROM training_detail AS s JOIN materi AS t JOIN training_history AS u JOIN employee AS v WHERE v.employee_id = $id1 AND s.nik LIKE v.nik AND u.id_materi LIKE t.id_materi AND s.id_riwayat_training LIKE u.id_riwayat_training ");
$i=1;
while($row1 = mysql_fetch_array($query))
{
$date = $row1['date'];
$subject1 = $row1['subject_name'];
?>
<tr>
<td class="table-bordered"><?php echo $i; ?></td>
<td class="table-bordered"><?php echo date("j/F/Y", strtotime($date)); ?></td>
<td class="table-bordered"><?php echo $subject1; ?></td>
<td class="table-bordered"><?php echo $row1['subject_no']; ?></td>
<td class="table-bordered"><?php echo $row1['revision_no']; ?></td>
<td class="table-bordered"><?php echo $row1['trainer']; ?></td>
<td class="table-bordered"><?php echo $row1['institution']; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</br>
<table class="table table-bordered">
<tr>
Training yang belum diikuti
<td class="table-bordered">No</td>
<td class="table-bordered"></td>
<td class="table-bordered">subject id</td>
<td class="table-bordered">subject namei</td>
<td class="table-bordered">subject no</td>
</tr>
<?php
$query = mysql_query("SELECT * FROM job_name AS r JOIN subject AS q JOIN employee AS p WHERE q.subject_id LIKE r.header_id AND r.job_id LIKE p.id_jabatan AND p.id_karyawan = $id1 ORDER BY q.id_materi ASC ");
$i=1;
while($row2 = mysql_fetch_array($query))
{
$subject2 = $row2['subject_name'];
if (strcasecmp($subject1, $subject2) == 0)
{
?>
<tr>
<td class="table-bordered"><?php echo $i; ?></td>
<td class="table-bordered"><?php echo "YES" ?></td>
<td class="table-bordered"><?php echo $row2['subject_id'] ?></td>
<td class="table-bordered"><?php echo $subject2; ?></td>
<td class="table-bordered"><?php echo $row2['subject_no']; ?></td>
</tr>
<?php
}
else
{
?>
<tr>
<td class="table-bordered"><?php echo $i; ?></td>
<td class="table-bordered"><?php echo "NO" ?></td>
<td class="table-bordered"><?php echo $row2['subject_id'] ?></td>
<td class="table-bordered"><?php echo $subject2; ?></td>
<td class="table-bordered"><?php echo $row2['subject_no']; ?></td>
</tr>
<?php
}
$i++;
}
?>
</table>
You need to use nested loop I guess. Use second while inside of first one.
BTW look at http://php.net/manual/en/control-structures.alternative-syntax.php, it might make your code seem better.