Well, Ann, we can help you, but, perhaps I am not clear. To help you, we need to understand your database tables. You are combining two tables, but, not in the correct manner. In your first post you are using WITH and in the last post, you put two tables in the FROM section. You can not do either of these. At least not the way you are using them. I will suggest some things to help you decide how to handle this.
First, are you just trying to list all the sub-goals for EVERY main-goal? OR, are you trying to just list the sub-goals for one main-goal that has already been selected?
If you already know the one main-goal, you would just use a simple query to the world_subgoal table to get all the correct data from that one main-goal number.
If you need to list all of the main-goals and show the sub-goals for each, you need to either do one main-goal at a time, or create a result array that contains all of the possible data. If you do that, you need to understand how to group the data resulting from the query. One problem with this is you must order the data correctly.
The easiest way is to use two queries and two loops. But, if you want to JOIN the two tables, we can do it that way also. I will attempt to explain both ways. First, the easy way:
(Not real code, just examples…)
SELECT id FROM world_goal ( Gets a list of ALL goals ) (Gets all main-goals)
Loop thru the results goal-by-goal
Use the world_goal_id to get all sub-goals
SELECT * FROM world_subgoal WHERE id_goal=$row[‘id’] (Gets all sub-goals for this one goal in loop)
Loop thru this second results sub-goal-by-sub-goal and display each
This way is simple enough with two queries and two resulting sets of data. Small number of lines.
The next way would be to JOIN two tables and you will get an array of data combined from both of your tables. You would get a final array that would include all the main-goals and all of the sub-goals. But, this way is harder to display since you must go thru each row of the results and figure out when to break on the main-goal id number. If you join two tables, you would get results loosely like…
main-goal-id, sub-goal-number
So, displaying them you would have to parse thru them with them ordered by main-goal. Then, list all of the sub-goals for each one. How to handle this depends on how you want to display them. Either way works.