Note that there are some explanatory texts on larger screens.

plurals
  1. POOutput a php multi-dimensional array to a html table
    primarykey
    data
    text
    <p>I have a form that has 8 columns and a variable number of rows which I need to email to the client in a nicely formatted email. The form submits the needed fields as a multidimensional array. Rough example is below:</p> <pre><code>&lt;input name="order[0][topdiameter]" type="text" id="topdiameter0" value="1" size="5" /&gt; &lt;input name="order[0][bottomdiameter]" type="text" id="bottomdiameter0" value="1" size="5" /&gt; &lt;input name="order[0][slantheight]" type="text" id="slantheight0" value="1" size="5" /&gt; &lt;select name="order[0][fittertype]" id="fittertype0"&gt; &lt;option value="harp"&gt;Harp&lt;/option&gt; &lt;option value="euro"&gt;Euro&lt;/option&gt; &lt;option value="bulbclip"&gt;Regular&lt;/option&gt; &lt;/select&gt; &lt;input name="order[0][washerdrop]" type="text" id="washerdrop0" value="1" size="5" /&gt; &lt;select name="order[0][fabrictype]" id="fabrictype"&gt; &lt;option value="linen"&gt;Linen&lt;/option&gt; &lt;option value="pleated"&gt;Pleated&lt;/option&gt; &lt;/select&gt; &lt;select name="order[0][colours]" id="colours0"&gt; &lt;option value="beige"&gt;Beige&lt;/option&gt; &lt;option value="white"&gt;White&lt;/option&gt; &lt;option value="eggshell"&gt;Eggshell&lt;/option&gt; &lt;option value="parchment"&gt;Parchment&lt;/option&gt; &lt;/select&gt; &lt;input name="order[0][quantity]" type="text" id="quantity0" value="1" size="5" /&gt; </code></pre> <p>This form is formatted in a table, and rows can be added to it dynamically. What I've been unable to do is get a properly formatted table out of the array.</p> <p>This is what I'm using now (grabbed from the net).</p> <pre><code>&lt;?php if (isset($_POST["submit"])) { $arr= $_POST['order'] echo '&lt;table&gt;'; foreach($arr as $arrs) { echo '&lt;tr&gt;'; foreach($arrs as $item) { echo "&lt;td&gt;$item&lt;/td&gt;"; } echo '&lt;/tr&gt;'; } echo '&lt;/table&gt;; }; ?&gt; </code></pre> <p>This works perfectly for a single row of data. If I try submitting 2 or more rows from the form then one of the columns disappears. I'd like the table to be formatted as:</p> <pre><code>| top | Bottom | Slant | Fitter | Washer | Fabric | Colours | Quantity | ------------------------------------------------------------------------ |value| value | value | value | value | value | value | value | </code></pre> <p>with additional rows as needed. But, I can't find any examples that will generate that type of table! </p> <p>It seems like this should be something fairly straightforward, but I just can't locate an example that works the way I need it too.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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