无法显示查询结果

时间:2019-10-30 01:15:24

标签: php html mysql

我似乎无法在HTML上显示查询结果。它什么也不显示。

我真的不知道该怎么做。

$qr1= mysqli_query($conn,"SELECT qr FROM `count` WHERE id=1;");
$qr2= mysqli_query($conn,"SELECT qr FROM `count` WHERE id=2;");
$qr3= mysqli_query($conn,"SELECT qr FROM `count` WHERE id=3;");
$qr4= mysqli_query($conn,"SELECT qr FROM `count` WHERE id=4;");
$qr5= mysqli_query($conn,"SELECT qr FROM `count` WHERE id=5;");

$total= $qr1 + $qr2 + $qr3 + $qr4 + $qr5;

我的HTML:

<tbody>
  <tr>
    <th scope="row">QR1</th>
    <td><?php echo $qr1 ?></td>
  </tr>
  <tr>
    <th scope="row">QR2</th>
    <td><?php echo $qr2 ?></td>
  </tr>
  <tr>
    <th scope="row">QR3</th>
    <td><?php echo $qr3 ?></td>
  </tr>
  <tr>
    <th scope="row">QR4</th>
    <td><?php echo $qr4 ?></td>
  </tr>
  <tr>
    <th scope="row">QR5</th>
    <td><?php echo $qr5 ?></td>
  </tr>
</tbody>

1 个答案:

答案 0 :(得分:1)

缺少的是您需要在$ qr上指定列。

这是您的代码的较短版本。

$total = 0;
$qr= mysqli_query($conn,"select qr, concat('QR', cast(id as varchar(3))) as id FROM `count` where id in (1,2,3,4,5) order by id;");
<tbody>
    while ($row = mysqli_fetch_row($qr)) {             
        <tr>
            <th scope="row">
                <?php echo $row['id'] ?> 
            </th>
            <td><?php echo $row['qr'] ?></td>
        </tr> 
        $total = $total + $row['qr'];
    }
</tbody>