duanjiang7505 2013-12-05 11:59
浏览 29
已采纳

怎么回声整个表? 现在我只得到最后一排

I have this code right now and I only get the last two rows, but I need to get as many as there are in the database with the html. Thank you in advance

      //We include the includes.php, which contains our db connection data.
       include("includes.php"); 
       //dbCon(); references the db connection data in includes.php - in other words we call a function.
     dbCon();
     $query = "SELECT * FROM product WHERE categoryid = 1;";
    $result = mysqli_query($dbc,$query) or die('Error querying database.');
      if (mysqli_num_rows($result) == NULL) {
     mysqli_close($dbc);header("Location:index.php?l=f");exit();
      }

    while ($row = mysqli_fetch_assoc($result)){
       $name = $row['name'];
        $price = $row['price'];
}

    echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
    echo "Price: "." "."<strong>".$price."</strong></br>";
  • 写回答

3条回答 默认 最新

  • douyiken0968 2013-12-05 12:02
    关注

    Move the echo to inside the loop

    while ($row = mysqli_fetch_assoc($result)){
        $name = $row['name'];
        $price = $row['price'];
        echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
        echo "Price: "." "."<strong>".$price."</strong></br>";
    
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

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