Forums

PHP

This topic is locked

Help with dynamic list relations

Posted 14 May 2003 14:21:32
1
has voted
14 May 2003 14:21:32 Adam Davies posted:
Can anyone show me the light on this problem im having.
I have two list boxes and a text area, number 2 list box is dependant on the choices of the first and then when the 2nd list box is chosen the result is shown in the text area, all items are dynamic (loaded from mysql).

the problem is when the you make a choice on the 2nd listbox the first reverts back to it's original state.

it may help if I include the link to the page I have it on
www.perfume.ie/locator.php

i know the soloution but not how to get there.
currently when you make a choice it returns to the page with the value in the url for example when you choose UK it returns with www.perfume.ie/locator.php?country_id=2 and when you then choose the couny it returns with www.perfume.ie/locator.php?county_id=89

now i know the soloution is to get it to add the two values together in the url so it reads: www.perfume.ie/locator.php?country_id=2&county_id=89 , but that is where I am stuck.

if anyone can help me with this it would be most appreciated (be gentle ima php learner)

forgot to say, the only working (where the result goes into the text area) is the choice UK, shropshire.

additional info is that im using dwmx 6.1 with mysql with php server model

Edited by - cotc2001 on 14 May 2003 14:25:00

Replies

Replied 20 May 2003 07:52:48
20 May 2003 07:52:48 Allan Kent replied:
heya,

since your counties would have to be linked to your country table by a foreign key, you could just use the country id of the selected county to set the selected country. You'll probably need an extra query to pick that up though. assuming your country menu is called 'country_id' and county menu is called 'county_id', once the user has selected the county, you would go through to a page locator.php?county_id=89, simply do a query before you display the countries:

<pre id=code><font face=courier size=2 id=code>"select country_id from counties where county_id=".$county_id; </font id=code></pre id=code>

and use the returned country_id as the selected item in your country menu.

hope that helps
allan
Replied 20 May 2003 08:24:39
20 May 2003 08:24:39 Adam Davies replied:
thanks, through trial and error I worked that out yesterday.

what is bizzare though (it works though) is that if you choose a country it returns the wrong country_id in the url but it still returns the correct recordset for the counties, for example if you choose USA it should return with the url country_id=1 but it returns country_id=2 , but it still fills the listbox with the values for USA.

Weird but it works.

Reply to this topic