dongtuan1594 2016-11-29 06:34
浏览 32
已采纳

while循环用于检索数据

I am trying to retrieve multiple cars from a car rental database based on the model, so if someone clicks on Ford it would retrieve all cars that have a Model ID of 2 for example. The current code I have only shows the first record in the database, how do I make a while loop that would echo the rows for each match?

$ModelID = $_GET['model_id'];

$result = mysqli_query($con, "SELECT RegNumber, Colour FROM Car WHERE ModelID = '$ModelID'");   

$row = $result->fetch_assoc();

echo $row["RegNumber"];
echo $row["Colour"];       
  • 写回答

2条回答 默认 最新

  • dongye3917 2016-11-29 06:40
    关注

    You need something like:

    while ($row = $result->fetch_assoc()) {
        echo $row['RegNumber'];
        echo $row['Colour'];
    }
    

    For more details, please go through the PHP Documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部