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条)

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导