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

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.