...

View Full Version : Viewing multiple fields in dynamic dropdowns.



swatisonee
11-19-2006, 08:55 AM
Hi,

I have the foll code for populating a dropdown based on the results of a selection in a primary dropdown. Problem is that when the 2nd d.d. is loaded, it only shows me the City and not the Province. Now I need to have both the fields appearing on the page so the user makes the correct selection.

The 2 tables are :

States with field names SID(int), State(varchar)
Cities with field names CITYID(int), SID(int), City(varchar) , Province(varchar)


Would really appreciate if someone could show me how to modify the foll line so that both city,province appear on the users screen in the dropdown box.


echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[CITYID]'>$noticia[City],$noticia[Province]</option>";


Thanks.

<? include("protect.php"); ?> // contains all db info

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Multiple drop down list box from plus2net</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='add_custadd1.php?cat=' + val ;
}

</script>
</head>

<body>
<?


mysql_connect("localhost", $dbname, $dbpasswd ) or die ("Unable to connect to server.");

mysql_select_db($database) or die ("Unable to select database.");


@$cat=$_GET['cat'];

$quer2 = mysql_query( "SELECT DISTINCT `State`, `SID` FROM `States` ");

if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT `City` FROM `Cities` where `SID`=$cat order by `City`");

}else{$quer=mysql_query("SELECT DISTINCT City FROM Cities order by City"); }

echo "<form method=post name=f1 action='add_custadd2.php'>";

echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['SID']==@$cat){echo "<option selected value='$noticia2[SID]'>$noticia2[State]</option>"."<BR>";}
else{echo "<option value='$noticia2[SID]'>$noticia2[State]</option>";}
}
echo "</select>";

echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[CITYID]'>$noticia[City],$noticia[Province]</option>"; // THIS STATEMENT ONLY SHOWS CITY AND NOT CITY,PROVINCE.
}
echo "</select>";

echo "<input type=submit value=Submit>";
echo "</form>";

?>

</body>

</html>

SeeIT Solutions
11-19-2006, 12:20 PM
You're not selecting province from the table.

Just change


$quer=mysql_query("SELECT DISTINCT `City` FROM `Cities` where `SID`=$cat order by `City`");

to


$quer=mysql_query("SELECT DISTINCT `City`,`Provnce` FROM `Cities` where `SID`=$cat order by `City`");

swatisonee
11-19-2006, 03:54 PM
am afraid didnt help.


$quer=mysql_query("SELECT DISTINCT `City`,`Province` FROM `Cities` where `SID`=$cat order by `City`");

Also changed the foll.


echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[City],$noticia[Province]'>$noticia[City],$noticia[Province]</option>";

I get the city name follwed by the Comma but the province name doesnt pop up.

Any thing else i could be checking for ?
Thanks !

swatisonee
11-20-2006, 05:12 AM
Aagh ! Spelling mistake ! Its working now. Thanks SeeIT Solutions !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum