Kholiq Fadli Kholiq Fadli - 1 month ago 7
PHP Question

How To Control Looping HTML Table PHP

So, i've table like in picture
enter image description here

I want put looping row person on left side to singgle row select box on right side, like by color. And this is a code table right side.

<table>
<tr>
<td>No.</td>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>

<?php if(!empty($query)) { $number=1 ; foreach($query as $row) { ?>
<tr>
<td>
<?php echo $number++ ?>.</td>
<td>
<?php echo $row->column_a ?></td>
<td>
<?php echo $row->column_b ?></td>
<td>
<?php echo $row->column_c ?></td>

</tr>
<?php }} ?>
</table>


How to control looping iteration, to make this is happen?
Tanks a lot.

Answer

My friend just help to fix my problem,

<table>
  <tr>
    <td>No.</td>
    <td>A</td>
    <td>B</td>
    <td>C</td>
  </tr>

  <?php if(!empty($query)) { $number=1;$count=0; foreach($query as $row) { ?>
<?php if($count % 3 == 0){ ?>
  <tr>
    <td>
      <?php echo $number++ ?>.</td>
<?php } ?>
    <td>
      <?php echo $row->column_a ?></td>
    <td>
      <?php echo $row->column_b ?></td>
    <td>
      <?php echo $row->column_c ?></td>
<?php $count++; if($count % 3 == 0){ ?>
  </tr>

  <?php }}} ?>
</table>