Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two possibilities that i can see see to accomplish what you need. Here is one; send two arrays to your view, one containing just the dates and the other containing the purchase information:</p> <p><strong>In the controller</strong></p> <pre><code>$page_data['purchase_dates'] = $this-&gt;yourmodel-&gt;get_purchase_dates($record_id); $page_data['purchases'] = $this-&gt;yourmodel-&gt;get_purchases($record_id); </code></pre> <p><strong>Note</strong> Make sure you use GROUP BY in your database query for the purchase dates.</p> <p><strong>In the View</strong></p> <pre><code>&lt;!-- Start Outer Tree Loop --&gt; &lt;?php if($purchase_dates != FALSE){?&gt; &lt;?php foreach($purchase_dates as $id=&gt;$outer_value) { ?&gt; &lt;!-- Output the date here --&gt; &lt;!-- Start Purchase table --&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Param One&lt;/th&gt; &lt;th&gt;Param Two&lt;/th&gt; &lt;th&gt;Etcetera&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;!-- Start inner loop --&gt; &lt;?php foreach($purchases as $id=&gt;$inner_value) { ?&gt; &lt;?php if($inner_value['purchase_date'] == $outer_value['purchase_date']) { ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $inner_value['Param One'] ?&gt; &lt;/td&gt; &lt;td&gt;&lt;?php echo $inner_value['Param Two'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $inner_value['Etcetera'] ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; &lt;!-- End inner loop --&gt; &lt;/table&gt; &lt;!-- End Purchase table --&gt; &lt;?php } ?&gt; &lt;?php }?&gt; &lt;!-- End Outer Tree Loop --&gt; </code></pre> <p>I have added comments to illustrate the code (this may be the best option for you as the array you posted is two dimensional).</p> <p><strong>The second:</strong> is to send a three dimensional array to the view and loop through it in a very similar fashion as above.</p> <pre><code>&lt;?php if($purchases != FALSE){?&gt; &lt;?php foreach($purchases as $id=&gt;$purchase_day) { ?&gt; &lt;?php foreach($purchase_day as $purchase) { ?&gt; &lt;!-- Output here --&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; &lt;?php }?&gt; </code></pre> <p>Hope this helps.</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