gpt4 book ai didi

php mysql 动态表显示带编号

转载 作者:行者123 更新时间:2023-11-29 14:12:30 24 4
gpt4 key购买 nike

我有一个页面,我使用 php 从 mysql 填充表。我有10张 table 。如果表中没有数据,则不显示该表。

我已经显示了编号,例如表一为“1”,表2为2,依此类推。现在如果表 3,6,9 没有数据,则页面将显示数字表 1,2,4,5,7,8,10。但我希望根据显示的表格数量进行编号。

$tbl2= "SELECT * FROM wp_health_aanvullend_moduliar WHERE health_id=$hid";
$rs2 = mysql_query($tbl2);
$count2 = mysql_num_rows($rs2);

<?php if($count2 > 0){?>

<table class="sub_front_efect" cellpadding="0" cellspacing="0" style=" border:none; margin:10px 0;">
<thead>
<tr>
<th colspan="100%" class="health_sub_front">Aanvullend moduliar</th></tr>
</thead>
<tbody>

<?php $wp_health_aanvullend_moduliar = "wp_health_aanvullend_moduliar";
$crows = $wpdb->get_results( "SELECT * FROM $wp_health_aanvullend_moduliar WHERE health_id=$hid");
foreach ($crows as $crow) {
$type = $crow->type ;
$price = $crow->price;


?>
<tr data-price="<?php echo $price; ?>"><td width="65%"><?php echo $type; ?></td><td style="border-right:1px solid #ccc;">&euro; <?php echo $price; ?></td></tr>
<?php
}
?>
</tbody>

<?php } ?>

如果所有表都有数据则全部显示。 tables with numbers逻辑是什么

谢谢

最佳答案

您应该在显示表格的循环内使用计数器。在所有没有内容的表格中,计数器不会增加。

关于php mysql 动态表显示带编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13246459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com