Reputation: 37
I have question like how to hide result if the previous record on loop like
$s="SELECT * from tabel";
$qs=mysqli_query($conn, $s);
echo "<table>";
while($rs=mysqli_fetch_assoc($qs)) {
$tgl=date("d.m.y",strtotime($rs['tgl']));
$kode=$rs['kode'];
$desc=$rs['desc'];
echo "<tr><td>$tgl</td><td>$kode</td><td>$desc</td></tr>";
}
echo "</table>";
Example the date on previous record is the same date on next record, if value print on table sheet it looks double, the records only print if change or different. The date is same on next record (do not print) when the date is change then print. Also code only print if the code is change or different with previous record
This picture and code may illustrate what my points on it question Thanks
Result:
<table>
<tr>
<td>DATE</td>
<td>KODE</td>
<td>DESC</td>
</tr>
<tr>
<td>2019-11-20</td>
<td>ISO123</td>
<td>Test</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Row</td>
</tr>
<tr>
<td></td>
<td>DEF00</td>
<td>Column</td>
</tr>
<tr>
<td>2019-11-21</td>
<td>CCV09</td>
<td>Change</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Value</td>
</tr>
<tr>
<td></td>
<td>TRI124</td>
<td>Hide</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Duplicate</td>
</tr>
</table>
Upvotes: 0
Views: 45
Reputation: 3476
Try the following code:
$prev_tg1 = $prev_kode = ''; //Create Placeholders.
while($rs=mysqli_fetch_assoc($qs)) {
$tgl = date("d.m.y",strtotime($rs['tgl']));
$kode = $rs['kode'];
$desc = $rs['desc'];
if( $prev_tg1 == $tg1 ) { //Check same as previous
$tg1 = ''; //set it to empty if same
} else {
$prev_tg1 = $tg1; //Update the Placeholder
}
if( $prev_kode == $kode ) {
$kode = '';
} else {
$prev_kode = $kode;
}
echo "<tr><td>$tgl</td><td>$kode</td><td>$desc</td></tr>";
}
Upvotes: 1