0

Hi
I have 2 drop down fields in an array:
The array works perfectly, (and is part of a longer form) but when I submit, the data disappears. I'm not that bothered about the 2nd drop down being sticky but really need the selection of the first drop down to remain after the submit.

Any help would be great....

<?php

@$cat=$_GET['cat']; // Use this line or below line if register_global is off
//@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT prop_type,proptype_id FROM prop_types order by prop_type"); 
///////////// End of query for first list box////////////

if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT prop_subtype FROM prop_subtypes where proptype_id=$cat order by prop_subtype"); 
} 
////////// end of query for second prop_subtype drop down list box ///////////////////////////


//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select One</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['proptype_id']==@$cat){echo "<option selected value='$noticia2[prop_type]'>$noticia2[prop_type]</option>"."<BR>";}
else{echo  "<option value='$noticia2[proptype_id]'>$noticia2[prop_type]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////
echo "<BR>";
?></td>
                </tr>
                
                  <tr>
                    <td class="maintextnopad">Subtype:</td>
                    <td align="left"><?php
//////////        Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select One</option>";
while($part = mysql_fetch_array($quer)) { 
echo  "<option value='$part[prop_subtype]'>$part[prop_subtype]</option>";
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////

?>
1
Contributor
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ebanbury
0

Hi I forgot to mention that the form method="get"
If the form method="post" then the 1st field selection remains in place, and only the second drop down goes back to 'please select'

However I need the form to be "get" as it brings back quite extensive search results, which require pagination on the page and the only way the pagination works is with "get"

So the question is how to make the dynamic arrays and fields sticky with "get"?

Many thanks - really grateful for the help.

0

Hi if anyone can help....below I've posted the code for making 1 dynamic dropdown sticky...but I'm getting completely stuck with how to apply this to my 2 -dropdown dynamic array above :-(

If anyone could help that would really be fantastic...

Here is the code for 1 dropdown:

<?php $query = @mysql_query('SELECT DISTINCT district_zone FROM property_districts')
	or die('Query failed: ' . mysql_error());
	
	//// Start SELECT PART
	$sticky = '';
	if(isset($_GET['submit'])) {
	$sticky = $_GET['district_zone'];
}
	$pull_zone = "\r\n<select name=\"district_zone\">\r\n";
	
	while ($line = mysql_fetch_array($query, MYSQL_NUM)) {
	$district = mysql_real_escape_string($line[0]);

	if ($line[0] == $sticky) {
	$pull_zone .= "<option value=\"$line[0]\" selected=\"selected\">$line[0] $line[1]\r\n</option>\n";
} else {
	$pull_zone .= "<option value=\"$line[0]\">$line[0] $line[1]\r\n</option>\n";
}
}

	echo '</select>';
	echo "$pull_zone";
//// end select
//// END DISTRICT PULLDOWN ?>
0

Hi...hope this helps anyone in the future...I've solved the issue of how to make the first dynamic dropdown sticky (very easy in the end)...but the same does not seem to apply for the second drop down.....:0)

It is all in this line (whole code further down)

echo "<option selected value='$noticia2[proptype_id]'  selected = selected >$noticia2[prop_type]</option>"."<BR>";
<?php

/*
If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care.
*/
@$cat=$_GET['cat']; // Use this line or below line if register_global is off
$quer2=mysql_query("SELECT DISTINCT prop_type,proptype_id FROM prop_types order by prop_type"); 

if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT prop_subtype FROM prop_subtypes where proptype_id=$cat order by prop_subtype"); 
} 
////////// end of query for second prop_subtype drop down list box ///////////////////////////

echo '<form method="get" action="testing_sticky.php">';

//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select One</option>";


while($noticia2 = mysql_fetch_array($quer2)) 
	{ 


	if ($noticia2['proptype_id']==$cat)
		{
		echo "<option selected value='$noticia2[proptype_id]'  selected = selected >$noticia2[prop_type]</option>"."<BR>"; 
		}
	else
		{
		echo  "<option value='$noticia2[proptype_id]'> $noticia2[prop_type]</option>";
		}
	}

echo "</select>";

//////////////////  This will end the first drop down list ///////////

echo "<BR>";

?>
  
  
  <?php
//////////        Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select One</option>";
while($part = mysql_fetch_array($quer)) { 
echo  "<option value='$part[prop_subtype]' >$part[prop_subtype]</option>";
}

 echo '<input type="submit" name="submit" value="Go">';
echo '</select><form>';
//////////////////  This will end the second drop down list ///////////
//// Add your other form fields as needed here/////

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.