Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulate php array into HTML table
    text
    copied!<p>Populate php array into HTML table</p> <p>I have data in a php array (say, $rows2) that gives the below output in key-value pairs. I am trying to format this data into an HTML table:</p> <pre><code>0 =&gt; Month: 1 =&gt; 07/2011, 2 =&gt; 7-8 3 =&gt; / 1432 A.H 4 =&gt; 5 =&gt; Location: 6 =&gt; Plainfield, 7 =&gt; NJ, 8 =&gt; USA 9 =&gt; Calculation Method: 10 =&gt; Value 10 11 =&gt; 12 =&gt; Juristic Method: 13 =&gt; Standard </code></pre> <p>I tried to use the below code to populate the table:</p> <pre><code>echo '&lt;table border=1&gt;'; while (list($key, $value) = each($rows2)) { echo $value2.$value; if($i%5 == 0){ echo '&lt;tr&gt;&lt;td&gt;'.$value2.'&lt;/td&gt;&lt;/tr&gt;'; } $value2=''; $i++; } echo '&lt;/table&gt;'; </code></pre> <p>I get the below output:</p> <pre><code>-------------------------------------------------------- Month: | 07/2011 | 7-8 | 1432 A.H -------------------------------------------------------- Location: | Plainfield | NJ | USA -------------------------------------------------------- Calculation | ValueX | Juristic | ValueY Method: | | Method: | -------------------------------------------------------- </code></pre> <p>I am trying to split the last row into 2 rows and then colspan the second to look like the below result.</p> <pre><code>-------------------------------------------------------- Month: | 07/2011 | 7-8 | 1432 A.H -------------------------------------------------------- Location: | Plainfield | NJ | USA -------------------------------------------------------- Calculation | ValueX Method: | -------------------------------------------------------- Juristic | ValueY Method: | -------------------------------------------------------- </code></pre> <p>Could someone please help? Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload