nestorvaldez Posted September 20, 2006 Share Posted September 20, 2006 I need some Help.I want to filter my data in two combo box field, retreiving the data form my mysql DB.Ex.I have three DB : country, city, customer; city is relationed with country; and customer with bothso I want that when I select on country in the Customer Form the script could show/filter only the cities that belong to this country..COUNTRY - id-countrynameCITY - id- cityname- countryCUSTUMER- id- name- country- city Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 20, 2006 Share Posted September 20, 2006 city and country is in customer why not echo the city form that table. Quote Link to comment Share on other sites More sharing options...
Jocka Posted September 20, 2006 Share Posted September 20, 2006 ok. so if the country table has an ide and city has an aread for the country, then ur set.Simply call the city by country:[code]// let's just say the country id is 2 //$country_id = 2;$sql = "SELECT * FROM CITY WHERE country='" . $cid . "'";$results = mysql_query($sql);while($row = mysql_fetch_rows($results)){ // HERES UR CITIES}[/code] Quote Link to comment Share on other sites More sharing options...
nestorvaldez Posted September 20, 2006 Author Share Posted September 20, 2006 Im getting problem doing it..The problem is, it is in the new record form Im try to register a new one.. So I dont have it the code in the DB, yet.. My problem is that I cant make refresh the page in order show the city in my combo, depending on the country I selected.. I mean the first field is the country and the next one is the City, then I want that when I select the One country and go out from this field to the next it make the refresh or what ever and show me in the next field (the Cities combo) just the cities from the country I selected...This is my code to select the country from the DB <select size="1" name="country" tabindex="13"> <?php $query = mysql_query("SELECT PAI_ID, PAI_NOMBRE FROM pais"); while ($row = mysql_fetch_array($query)) { $pid=$row['PAI_ID']; $pnombre=$row['PAI_NOMBRE']; ?> <option value="<?=$pid?>" <?//=$selected?>><?=$pnombre?></option> <? } ?> </select> and this is to select the City: <select size="1" name="city" tabindex="12"> <?php $query = mysql_query("SELECT CIU_ID, CIU_NOMBRE FROM ciudad" WHERE CIU_PAIS=$pid); while ($row = mysql_fetch_array($query)) { $cid=$row['CIU_ID']; $cnombre=$row['CIU_NOMBRE']; ?> <option value="<?=$cid?>" <?//=$selected?>><?=$cnombre?></option> <? } ?> </select>How to refresh dinamically when the focus leave the Country field Quote Link to comment Share on other sites More sharing options...
Jocka Posted September 20, 2006 Share Posted September 20, 2006 well you have a problem with your code i noticed immediatly.. this:<option value="<?=$pid?>" <?//=$selected?>><?=$pnombre?></option>should be more like this:<option value="<? echo $pid; ?>" <? echo $selected; ?><? echo $pnombre; ?></option>and you can refresh using javascript. I'm not real good with javascript but a search on google should come up with good results. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.