duanlu1793 2016-09-17 20:08
浏览 34
已采纳

数据库中的第一行没有在mysql_fetch_row或mysql_fetch_assoc的表中显示

Though these questions have already been answered and i have tried to follow those, yet the first row from mysql database is not getting displayed in the table. (I have three rows)

Following is my code. Will be very kind of you if you can help. Thank You.

<?php 

require_once 'dbreg.php';
?>

<!DOCTYPE html>
<head>
<title>User Listing</title>
</head>
<body>
<table border="1">
    <tr>
        <td>Firstname</td>
        <td>Lastname</td>
        <td>Gender</td>
        <td>Address</td>
        <td>Country</td>
        <td>Actions</td>
    </tr>

    <?php
    $query = mysql_query("SELECT * FROM regform");
    if(mysql_fetch_row($query) > 0) {
        while ($result = mysql_fetch_assoc($query)) {




            ?>

            <tr>

                <td><?php echo $result['firstname'];?></td>
                <td><?php echo $result['lastname'];?></td>
                <td><?php echo $result['gender'];?></td>
                <td><?php echo $result['address'];?></td>
                <td><?php echo $result['country'];?></td>
                <td><a href="view.php">View</a> /<a href="#"> Edit</a></td>
            </tr>

            <?php
        }
        }

    ?>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • douzhao5656 2016-09-17 20:12
    关注

    "if(mysql_fetch_row($query) > 0) {" line is reading already the result-set moving the cursor forward so when code execution gets to the "while ($result = mysql_fetch_assoc($query)) {" line it is already at second row in result-set. You should remove the "if line" because while will act exactly as you expect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 请教一下c语言的代码里有一个地方不懂
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档