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.

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

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改