如果先前的记录相同,则在表上隐藏结果

我有一个问题,如果循环上的前一个记录像这样,如何隐藏结果


$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>";

例如,上一条记录上的日期与下一条记录上的日期相同,如果在表格上打印的值看起来是双倍的,则只有在更改或不同时才会打印记录。当日期更改然后打印时,下一条记录的日期相同(不打印)。此外,仅在代码更改或与先前记录不同时才打印代码


这张图片和代码可以说明我对此问题的观点谢谢

http://img2.mukewang.com/61d821640001412e02370302.jpg

http://img.mukewang.com/61d8216d0001646a02290299.jpg

结果:


<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>


慕仙森
浏览 127回答 1
1回答

湖上湖

试试下面的代码:$prev_tg1 = $prev_kode = '';&nbsp; //Create Placeholders.while($rs=mysqli_fetch_assoc($qs)) {&nbsp; &nbsp; $tgl = date("d.m.y",strtotime($rs['tgl']));&nbsp; &nbsp; $kode = $rs['kode'];&nbsp; &nbsp; $desc = $rs['desc'];&nbsp; &nbsp; if( $prev_tg1 == $tg1 ) {&nbsp; //Check same as previous&nbsp; &nbsp; &nbsp; &nbsp; $tg1 = '';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //set it to empty if same&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; $prev_tg1 = $tg1;&nbsp; &nbsp; &nbsp; //Update the Placeholder&nbsp; &nbsp; }&nbsp; &nbsp; if( $prev_kode&nbsp; == $kode ) {&nbsp; &nbsp; &nbsp; &nbsp; $kode = '';&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; $prev_kode&nbsp; = $kode;&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp; echo "<tr><td>$tgl</td><td>$kode</td><td>$desc</td></tr>";}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript