A Looooooooop question
Posted: Wed Sep 11, 2002 2:56 am
Hi,
I'm in my second week now learning PHP from a book called "PHP 4 Zonder stress" (= wihtout stress) but I'm getting very frustrated.
Discription of my problem:
I have 2 tables:
Table_1: country
fields:
countr_id | country_name
values:
ES | Spain
FR | France
Table_2: region
fields:
region_id | region_name | country_id
values:
CB | Costa Brava | ES
CD | Costa Dorada | ES
CA | Costa Azahar | ES
LA | Languedoc | FR
RO | Roussilon | FR
I want to display a list as follows:
Spain
Costa Brava
Costa Dorada
Costa Azahar
France
Languedoc
Roussillon
I succeded to display it like this, but not in a correct way:
Explanation:
I use 2 querys:
a) query of all the regions within Spain
b) query of all the regions within France
To display it is use mysql_fetch_arry like this
<tr>
<td>
SPAIN (is simply typed)
</td>
</tr>
<tr>
<td>
while () { ==> regions spain
</td>
</tr>
<tr>
<td>
FRANCE (is simply typed)
</td>
</tr>
<tr>
<td>
while () { ==> regions france
</td>
</tr>
Problem: manual work if a new country and regions are added.
I managed to solve that problem and getting a list like this:
Spain Costa Brava
Spain Costa Dorada
etc..
France Languedoc
ect.
By using a 2 column table and the mysql_fetch_array and using only 1 query
But thats not what I want it to look like.
Question:
How can I display it as mentionned above and still have the automatic update if regions or countries are added using as less code and queries as possible ?
Thanks in advance,
Gijs
I'm in my second week now learning PHP from a book called "PHP 4 Zonder stress" (= wihtout stress) but I'm getting very frustrated.
Discription of my problem:
I have 2 tables:
Table_1: country
fields:
countr_id | country_name
values:
ES | Spain
FR | France
Table_2: region
fields:
region_id | region_name | country_id
values:
CB | Costa Brava | ES
CD | Costa Dorada | ES
CA | Costa Azahar | ES
LA | Languedoc | FR
RO | Roussilon | FR
I want to display a list as follows:
Spain
Costa Brava
Costa Dorada
Costa Azahar
France
Languedoc
Roussillon
I succeded to display it like this, but not in a correct way:
Explanation:
I use 2 querys:
a) query of all the regions within Spain
b) query of all the regions within France
To display it is use mysql_fetch_arry like this
<tr>
<td>
SPAIN (is simply typed)
</td>
</tr>
<tr>
<td>
while () { ==> regions spain
</td>
</tr>
<tr>
<td>
FRANCE (is simply typed)
</td>
</tr>
<tr>
<td>
while () { ==> regions france
</td>
</tr>
Problem: manual work if a new country and regions are added.
I managed to solve that problem and getting a list like this:
Spain Costa Brava
Spain Costa Dorada
etc..
France Languedoc
ect.
By using a 2 column table and the mysql_fetch_array and using only 1 query
But thats not what I want it to look like.
Question:
How can I display it as mentionned above and still have the automatic update if regions or countries are added using as less code and queries as possible ?
Thanks in advance,
Gijs