Using Multiple FOREACH to display hierarchical data from MySQL table using PHP
<p>Studying and using PHP here. I am having trouble with using FOREACH to loop the contents of a table. Here's my situation:</p>

<p>I have a table in MySQL with four columns as Strategy, Objective, Commitment, Person. As you may guess, Strategy, Objective, and Commitment are levels for each person, with Strategy as the highest level, followed by Objective, and lastly Commitment. That is, one Strategy may have multiple Objective items, each of which may have multiple Commitment items.</p>

<p>What I'm trying to do is to create FOREACH loops that will do the following:</p>

<ol>
<li>Select and display the Strategy items that are presented for a given Person.</li>
<li>For each Strategy item, it should search available Objective items for that Person.</li>
<li>For each Objective item, the code should search and display available Commitment items for that Person.</li>
</ol>

<p>I will display the items in a table, with the Strategy and Objective items spanning 3 columns. The organization in the table should reflect the indicated hierarchy: Strategy -> Objective -> Commitment, like below:</p>

<p>| Strategy1       |<br />
| Objective1      |<br />
| Commitment1     |<br />
| Objective2      |<br />
| Commitment2     |<br />
| Strategy2       |<br />
| Objective3      |<br />
| Commitment3     |<br />
| Commitment4     |<br /></p>

<p>Can anyone help?</p>

<p>Thanks!</p>