-3

how can I separate the same numbers with hr line? The numbers are pulled from the db row. example:

1
1
1
<hr>
----------
2
2
2
<hr>
---------- 
<?php
$result=mysqli_query($con,"SELECT * FROM homepage order by bangdbs");
while($row=mysqli_fetch_array($result)) {
    echo "<td align='left'>".$row['site_id']."</td>";
    if($site_id) {
        echo '<tr onclick="toggle(this)" style=""><td colspan="7"><hr noshade="" style="color:#F34105;"></td></tr>';
    }
}
?>
4

3 回答 3

1
$last = -1;
while($row = mysqli_fetch_array($result))
 {
 if( $last <> $row['site_id'])
   {
    echo "<hr>";
    $last = $row['site_id'];
   }
 echo $row['site_id'];
 }
于 2013-10-16T18:58:17.613 回答
1
$previous_site_id = 0;
while($row = mysqli_fetch_array($result)) {
    echo "<td align='left'>" . $row['site_id'] . "</td>";
    if ($previous_site_id && $row['site_id'] != $previous_site_id) {
        // insert your <hr> construct here
        $previous_site_id = $row['site_id'];
    }
}

请注意,关于 HTML,您的示例缺少一些要点,解决方案也是如此。无论如何,这不是一个真正的问题,我只是在演示如何做到这一点。

于 2013-10-16T18:59:40.480 回答
-1

通过 sql 检查先前的值并存储它们

<?php
$que = "SELECT * FROM homepage order by bangdbs";
$res = mysql_query($que, $con);
if(mysql_num_rows($res)>0){
while($row = mysql_fetch_array($res))
{ 
$idminus1=$row['id']-1;
$que2=mysql_query(select * from homepage where id='$idminus1' );
$previousvalue=$que2['site_id']

if($row['site_id'] == $previousvalue)
{
echo $row['site_id'];
}else{
echo "<hr>";


}}

?>

这就是整个代码

于 2013-10-16T18:59:59.427 回答