troubleshooting Question

How do I dynamically generate Table Cells based on variable content?

Avatar of ggjones
ggjonesFlag for Afghanistan asked on
PHP
7 Comments3 Solutions208 ViewsLast Modified:

Hi there...

I need to dynamically populate up to 6 table cells in three rows of two columns each:

<table  border="0" cellpadding="0" cellspacing="0" style='width:1000px;'>
<tr>
<td style='width:50%;'></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>

The data comes from an array containing up to six arrays, each one containing a comma-delimited list.

$metaArray = array($array1, $array2, $array3, $array4, $array5, $array6);

However, the array may contain as little as 1 array, in which case the table should have a single cell only:

$metaArray = array($array3);

<table  border="0" cellpadding="0" cellspacing="0" style='width:1000px;'>
<tr>
<td style='width:100%;'></td>
</tr>
</table>

But if the array contains , say only 3 arrays, it should have three cells, thusly:

$metaArray = array($array1, $array3, $array6);

<table  border="0" cellpadding="0" cellspacing="0" style='width:1000px;'>
<tr>
<td style='width:50%;'></td>
<td></td>
</tr>
<tr>
<td colspan="2"style='width:100%;'></td>
</tr>
</table>

... and so on.

The order in which the cells are populated is important also - they need to follow their key order.

Could I get some help please, with the logic and syntax?

Many, many thanks,

GJ
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros