gpt4 book ai didi

PHP for 循环 - 在表中显示数据

转载 作者:行者123 更新时间:2023-11-29 04:49:26 25 4
gpt4 key购买 nike

我不明白为什么我的代码不起作用;它只显示 1 个结果,而表中有多个条目..

<?php  

$search = $_POST['search'];
print ($search);
$query = "SELECT * FROM student WHERE county= 'sussex'";
$result = mysql_query($query,$conn);
$counter = 0;
$z=0;
while($row = mysql_fetch_assoc($result)){
$id[$counter] = $row['roll_number'];
$counter = $counter + 1;
}
?>
<table border="1" id="table1" >
<th>Id</th>
<th>Type</th>
<th>Description</th>
<th>Operator Id</th>

<?
if($counter>0)
{
for($z=0;$z<$counter;$z++)
{
?>
<tr>
<?
if($z<$counter)
{
?>
<td >
<?php echo $id[$z]?>
</td>
<?
}
$z = $z + 1;
?>
</tr>
</table>

最佳答案

您忘记关闭 FOR 循环及其封闭的 IF,我已经在下面完成了:

<?
if($counter>0)
{
for($z=0;$z<$counter;$z++)
{
?>
<tr>
<?
if($z<$counter)
{
?>
<td >
<?php echo $id[$z]?>
</td>
<?
}
//$z = $z + 1; <!-- REMOVE or comment out this line -->
?>
</tr>
<? }
} ?> <!-- HERE we close the for loop and the IF -->
</table>

更新:注意到,感谢 VinceBurn,$z 增加了两次

关于PHP for 循环 - 在表中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13542968/

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