Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to display comma separated values from multiple columns in php inside html table

i have an sql table with three columns which have comma separated values, i am trying to print it inside an html table, my code looks like below:

<table class="table custom-table m-0">
  <thead>
    <tr>
      <th>Description</th>
      <th>Make</th>
      <th>UOM</th>
    </tr>
  </thead>
  <tbody>

    <?php 
    $one=explode(',', $row['description']);
    $two=explode(',', $row['make']);
    $three=explode(',', $row['uom']);
    foreach($one as $ones) {
     ?>
    <tr>
      <td>
        <?php echo $ones?>
      </td>
      <td></td>
      <td></td>

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

here am only able to get the values of first column, can anyone please tell me how to get values from all the three columns, thanks in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use a counter – assuming exact same number of entries per row

http://sandbox.onlinephpfunctions.com/code/555be47daf3bc3e99d496585f702bfc9dfae4e4e

<? 
$one=explode(',', $row['description']);
$two=explode(',', $row['make']);
$three=explode(',', $row['uom']);    
$i=0;
?>

<table class="table custom-table m-0">
  <thead>
    <tr>
      <th>Description</th>
      <th>Make</th>
      <th>UOM</th>
    </tr>
  </thead>
  <tbody>

    <?php 
    foreach($one as $ones) {
     ?>
    <tr>
      <td><?php echo $ones; ?></td>
      <td><?php echo $two[$i]?></td>
      <td><?php echo $three[$i]?></td>

    </tr>
    <?php $i++;}?>
  </tbody>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading