drh78568 2019-02-05 04:48
浏览 72
已采纳

显示包含选项中数据的所有记录

I want to echo all of the data that contains the selected option but every time I echo those data, I only get one.

the select is use for filtering the search, here's my code

<select class = "grade" name = "grade">
<option value ="" >=====Grade=====</option>
            <option value ="Grade11">Grade 11</option>
            <option value ="Grade12">Grade 12</option>
</select>
<input type="submit" name="search" value= "Submit">

</div>
<div class = "records">
    <table width ="600" border = "1" cellpadding ="1" cellspacing ="1">
        <tr>
            <th>Last Name</th>
            <th>First Name</th>
            <th>Middle Name</th>
</tr>
</table>
<?php
if (isset($_POST['search'])) {


    $grade =$_POST['grade'];
    $sql = "SELECT * FROM student WHERE grade ='$grade'";
    $result = mysqli_query($conn, $sql);
    $row = mysqli_fetch_assoc($result);

   echo "<tr>";
        echo "<td>".$row['lname']."</td>";
   echo "</tr>";

}
  • 写回答

1条回答 默认 最新

  • drkjzk3359 2019-02-05 04:55
    关注

    You missed while loop.. It will print all data from result..

    while($row = mysqli_fetch_assoc($result))
    {
       echo "<tr>";
            echo "<td>".$row['lname']."</td>";
       echo "</tr>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)