Jump to content

creating table from string


max_w1

Recommended Posts

I have a string (Product1-Product2-Product3#2-4-1) where Product1-Product2-Product3 are products and 2-4-1 are quantities. I am struggling to make a table out of it where products and quantities are shown in rows.

 

here is what i tried.

 

list($products, $quantities) = explode("#", $specs); //to separate Quantities from products

<?php foreach(preg_split("/-/", $products) as $product_list) { ?>
  
  <tr>
    <td> <?php echo $product_list; ?></td><? } ?> <?php foreach(preg_split("/-/", $quantities) as $qtylist) { ?>   <td></td>
    <td><?php echo $qtylist; ?></td> <?php } ?>
  </tr> 

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

 

I know something is wrong with this and its giving me unexpected reasult :(

 

Please help me create a table out of the above string.

 

Many Thanks

-Max

Link to comment
https://forums.phpfreaks.com/topic/259376-creating-table-from-string/
Share on other sites

Something like...

list($products, $quantities) = explode("#", $specs); //to separate Quantities from products
$p_1 = explode("-", $products);
$q_1 = explode("-", $quantites);
$x = count ($p_1);
?>
<table>
<?PHP
for($i=0;$i<$x;$i++) (
?>  
  <tr><td><?php echo $p_1[$i]; ?></td><td><?PHP echo $q_1[$i]; ?></td></tr> 
<?PHP
}
</table>

a badly deformed table, with rows and columns all messed up.

 

Here is the Table code i got from FireBug after compiling in firefox.

<table width="200" border="1">
<tbody>
<tr>
<td>Product Name </td>
<td>Quantity</td>
<td>Price</td>
</tr>
<tr>
<td> 2600x5</td>
<td> NMx001</td>
<td></td>
<td>2</td>
<td></td>
<td>9</td>
</tr>
</tbody>
</table> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.