Jump to content

Help With $_get Please


hane
 Share

Recommended Posts

Good morningI need some help with my code please. I works in the sense that it does what i want it to do except on my second reload I loose the first selected value. eg. select [1] classifieds from first drop down reloads url = menu_l.php?dat=1 Select [1]antiques from second drop down reloads and populate 3rd drop down. Here is my problem on the second reload url = menu_l.php?dat=0&cat=1. The dat must = first selected value but it doesnt. Please help.

<script language=JavaScript>function reload1(form){var val1=form.dat.options[form.dat.options.selectedIndex].value; self.location='menu_l.php?dat=' + val1;}function reload(form){var val1=form.dat.options[form.dat.options.selectedIndex].value; var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='menu_l.php?dat=' + val1 + '&cat=' + val;}</script><?php$data=$_GET['dat']; echo "<form method=get name=f2 action=''>";echo "<select name='dat' onchange=\"reload1(this.form)\"><option value='0'>Select</option>";echo "<option value='1'>Classifieds</option>";echo "<option value='2'>Directory</option>";echo "</select>"; echo "<br /><br />";	if ($data == "1")	{	  $quer2=mysql_query("SELECT DISTINCT c_category_name,c_category_id FROM c_category order by c_category_name");  	  $cat=$_GET['cat']; 	if(isset($cat) and strlen($cat) > 0){	$quer=mysql_query("SELECT DISTINCT c_subcategory_name,c_subcategory_id FROM c_subcategory where c_category_id=$cat order by c_subcategory_name");	}	  else{$quer=mysql_query("SELECT DISTINCT c_subcategory_name, c_subcategory_id FROM c_subcategory order by c_subcategory_name"); 	  }	  	  echo "<form method=post name=f1 action='classified_show.php'>";	echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select Category</option>";	while($noticia2 = mysql_fetch_array($quer2)) {	if($noticia2['c_category_id']==@$cat){	  echo "<option selected value='$noticia2[c_category_id]'>$noticia2[c_category_name]</option>"."<BR>";}	else{echo "<option value='$noticia2[c_category_id]'>$noticia2[c_category_name]</option>";}	}	echo "</select>";	echo "<br /><br />";	echo "<select name='subcat'><option value=''>Select Subcategory</option>";	  echo "<option value='1'>All</option>";	while($noticia = mysql_fetch_array($quer)) {	echo "<option value='$noticia[c_subcategory_id]'>$noticia[c_subcategory_name]</option>";	}	echo "</select>";	echo "<br /><br />";	  	  $query="SELECT area_name,area_id FROM area order by area_name";   	$result = mysql_query ($query);	  	echo "<select name='area' > <option value=''>Select Area</option>";  	while($nt=mysql_fetch_array($result)){	echo "<option value=$nt[area_id]>$nt[area_name]</option>";	}	echo "</select>"; 	  echo "<br /><br />";	echo "<input type=submit value=Submit>";	echo "</form>";  }	else	{	  $quer2=mysql_query("SELECT DISTINCT d_category_name,d_category_id FROM d_category order by d_category_name");  	  $cat=$_GET['cat']; 	if(isset($cat) and strlen($cat) > 0){	$quer=mysql_query("SELECT DISTINCT d_subcategory_name,d_subcategory_id FROM d_subcategory where d_category_id=$cat order by d_subcategory_name");	}	  else{$quer=mysql_query("SELECT DISTINCT d_subcategory_name,d_subcategory_id FROM d_subcategory order by d_subcategory_name"); 	  }	  	  echo "<form method=post name=f1 action='../directory_show.php'>";	echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";	while($noticia2 = mysql_fetch_array($quer2)) {	if($noticia2['d_category_id']==@$cat){echo "<option selected value='$noticia2[d_category_id]'>$noticia2[d_category_name]</option>"."<BR>";}	else{echo "<option value='$noticia2[d_category_id]'>$noticia2[d_category_name]</option>";}	}	echo "</select>";	echo "<br /><br />";	echo "<select name='subcat'><option value=''>Select one</option>";	   echo "<option value='1'>All</option>";	while($noticia = mysql_fetch_array($quer)) {	echo "<option value='$noticia[d_subcategory_id]'>$noticia[d_subcategory_name]</option>";	}	echo "</select>";	echo "<br /><br />";	  $query="SELECT area_name,area_id FROM area order by area_name";   	$result = mysql_query ($query);	  	echo "<select name='area' > <option value=''>Select one</option>";		while($nt=mysql_fetch_array($result)){	echo "<option value=$nt[area_id]>$nt[area_name]</option>";	}	echo "</select>"; 	  echo "<br /><br />";	echo "<input type=submit value=Submit>";	echo "</form>";  }		  mysql_close($con);?>

Link to comment
Share on other sites

Guest Mark Cunningham

Your code is overly complex can you trim it down a little just the important parts.Also why not just print_r($_GET[*]) at the top to see what your getting from your $_GET its trial and error that will solve the problem.If you're not getting the variable that you want, then you know where the problem lies!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...