Hoi
Ik heb op allerhande sites gezeten om erachter te komen wat ik fout heb gedaan, maar allemaal zonder vruchten af te werpen... Het probleem is het dat de eerste dropdown geen gegevens uit de DB opneemt en daadoor de tweede dropdown niet juist filterd (moet ie dus doen a.h.v. de eerste). Wat momenteel het resultaat is, ts dat dropdown 2 ALLE gegevens laat zien (ongefilter, wel de correcty array) maar dropdown 1 helemaal niets, dus filteren gaat niet.
Eens stukje uit de SQLdump:
CREATE TABLE `re2_listings` (
`ListingID` int(10) NOT NULL auto_increment,
`AgentID` int(10) NOT NULL default '0',
`CategoryID` int(10) NOT NULL default '0',
`SubcategoryID` int(10) NOT NULL default '0',
`address` text NOT NULL,
`city` varchar(100) NOT NULL default '',
`state` varchar(100) NOT NULL default '',
`country` varchar(150) NOT NULL default '',
en de gebruikte code:
<?
require_once("conn.php");
connecttodb($db_host,$db_name,$db_username,$db_password);
function connecttodb($db_host,$db_name,$db_username,$db_password)
{
global $link;
$link=mysql_connect ("$db_host","$db_username","$db_password");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$db_name",$link) or die ("could not open db".mysql_error());
}
//////// End of connecting to database ////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.search_country.options[form.search_country.options.selectedIndex].value;
self.location='mainsearch.php?search_country=' + val ;
}
</script>
</head>
<body>
<?
@$search_country=$_GET['search_country']; // Use this line or below line if register_global is off
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT country FROM re2_listings order by country");
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($search_country) and strlen($search_country) > 0){
$quer=mysql_query("SELECT DISTINCT city FROM re2_listings where search_country=$search_country order by city");
}else{$quer=mysql_query("SELECT DISTINCT city FROM re2_listings order by city"); }
echo "<form method=post name=f1 action='search.php'>";
////////// Starting of first drop downlist /////////
echo "<select name='search_country' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['search_country']==@$search_country){echo "<option selected value='$noticia2[search_country]'>$noticia2[search_country]</option>"."<BR>";}
else{echo "<option value='$noticia2[search_country]'>$noticia2[search_country]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='city'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[city]'>$noticia[city]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<input type=submit value=Submit>";
echo "</form>";
?>
<center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center>
</body>
</html>
327 views