0

I can't seems to display the query results on my HTML. It displays nothing.

And I really don't know how to do that.

$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;

My 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 Answers1

1

what's missing is that you need to specify the column on your $qr.

Here's the shorter version of your code.

$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>
Ed Bangga
  • 12,879
  • 4
  • 16
  • 30