Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP for循环-在表中显示数据_Php_Html_Mysql - Fatal编程技术网

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

PHP for循环-在表中显示数据,php,html,mysql,Php,Html,Mysql,我不明白为什么我的代码不起作用;它只显示一个结果,而表中有多个条目。 <?php $search = $_POST['search']; print ($search); $query = "SELECT * FROM student WHERE county= 'sussex'"; $result = mysql_query($query,$conn); $counter = 0; $z=0; while($row = my

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

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

身份证件
类型
描述
操作员Id

您忘了关闭FOR循环及其封装,如果我已完成以下操作:

<?
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增加了两倍

您忘了关闭FOR循环及其封装,如果我在下面做了:

<?
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增加了两次

,而且您在两个不同的位置增加了$z。它仍然不起作用……它的显示1条目和html页面上的这一行。0){for($z=0;$zAnd)另外,您正在2个不同的位置递增$z。它仍然不工作…它的显示1项和html页面上的这一行。0){for($z=0;$z
SELECT*FROM student WHERE country='sussex'
-在sussex中查找学生时遇到问题!
SELECT*FROM student WHERE country='sussex'
-在sussex中查找学生时遇到问题!