Click here to Skip to main content
15,906,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good Day all

i am facing a challenge with my code. what i am trying to do is have two comboboxes one called province and the other one city, when the user selects a province it should only display the cities in that province in the city combobox. how can i achive this using PHP ?
PHP
function getCity($provinceId)
    {
        $sql ="SELECT `cityid`,`cityname` FROM `tblcity` inner join `tblprovince` ON `tblcity`.`pid`='$provinceId'  order by `cityid` asc";
        $query = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
			$row = mysql_fetch_assoc($query);		
			while($row)
			{
			$id = $row['cityid'];
			$name = $row['cityname'];
			echo 
			"
				<option value ='$id'>".$name."</option>
			";  
			$row = mysql_fetch_assoc($query);
		   }
     }


this is what my fuction looks like now i am unable to retrieve the values of the province combo box. any help will be appreciated.

Thanks in advance
Posted
Updated 11-Mar-13 10:01am
v2
Comments
Matej Hlatky 11-Mar-13 17:03pm    
The option should be inside select element, which should be inside form element. Is it so?
You can access form values from $_GET or $_POST php predefined variables.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900