问题描述:

Studying and using PHP here. I am having trouble with using FOREACH to loop the contents of a table. Here's my situation:

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.

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

  1. Select and display the Strategy items that are presented for a given Person.
  2. For each Strategy item, it should search available Objective items for that Person.
  3. For each Objective item, the code should search and display available Commitment items for that Person.

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:

| Strategy1 |

| Objective1 |

| Commitment1 |

| Objective2 |

| Commitment2 |

| Strategy2 |

| Objective3 |

| Commitment3 |

| Commitment4 |

Can anyone help?

Thanks!

相关阅读:
Top