Page 1 of 1

Dinamicall list menu, or how to make it remember selections?

Posted: Tue Mar 18, 2003 12:38 pm
by Igguana
I did a search engine to attack a database that takes the fields from the database itself :roll: by doing querys.
Then you have a bunch of list menus and a jump menu.
One of the list menus depends on the jump one because its contents are related to a previous selection, so when somebody choose and option for the jump menu, the page reloads and then this list menu is filled with options (the rest where filled from the begining)
What happens is that if the user has already filled all the fields, when the page reloads, he will realice that everything is empty again.
I have manage a system to prevent this in the jump menu, but this is not worth for the lists.
Some light over this?
<?
$base="bla";
$tabla="DatosInmueble";
$conexion=mysql_connect("bla");
mysql_select_db($base,$conexion);
$pegar1 = "SELECT Modo FROM $tabla GROUP BY Modo";
$pegar2 = "SELECT Localidad FROM $tabla GROUP BY Localidad";
$pegar3 = "SELECT Tipo FROM $tabla GROUP BY Tipo";
$pegar4 = "SELECT Habitaciones FROM $tabla GROUP BY Habitaciones";
$pegar5 = "SELECT Precio FROM $tabla GROUP BY Precio";
?>
<script language="JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<table width=100% border=0>
<tr>
<td bgcolor='#CCCC00'>
<form name='form1' method='post' action='resultados2.html'>
<table width='50%' border='0'>



<tr>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'>Modalidad</font></td>
<td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFF00">Localidad</font></td>
<td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFF00">Zona</font></td>
<td> </td>
</tr>
<tr>
<td> <font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<select name='envio1' size='1'>
<option value="-1"></option>
<?
$resultado1 = mysql_db_query($base,$pegar1)or die (mysql_error());
while ($registro1['Modo'] = mysql_fetch_row($resultado1)){
foreach($registro1['Modo'] as $clave1){
}
?>
<option><?

echo $clave1;
}

?></option>
</select>
</font></td>
<td> <font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<select name="saltador" onChange="MM_jumpMenu('parent',this,0)">
//with this functions I can make the jump menu keep the preselected option even though the page reloads.
<option value="<?
function devuelvedato ()
{
$nulo=-1;
global $var1;
if (isset($var1))
echo $var1;
else
echo $nulo;
}
devuelvedato();
?>" selected>
<?
function devuelvedato2 ()
{
$nulo2="";
global $var1;
if (isset($var1))
echo $var1;
else
echo $nulo2;
}
devuelvedato2();
?></option>
<?
$resultado2 = mysql_db_query($base,$pegar2)or die (mysql_error());
while ($registro2['Modo'] = mysql_fetch_row($resultado2)){
foreach($registro2['Modo'] as $clave2){
}
?>
<option value="buscadorpruebas2.php?var1=<? echo $clave2; ?>"><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFF00"><?
echo $clave2;
Here I sent the info to the reloaded page to know which option was selected in the jump menu
}
$pegar6 = "SELECT Zona FROM $tabla WHERE (Localidad='$var1') GROUP BY Zona";
?>
</font></option>
</select>
</font></td>
<td> <font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<select name='envio6' size='1'>
<option value="-1"></option>
<?
$resultado6 = mysql_db_query($base,$pegar6)or die (mysql_error());
while ($registro6['Habitaciones'] = mysql_fetch_row($resultado6)){
foreach($registro6['Habitaciones'] as $clave6){
}
?>
<option><?

echo $clave6;
}

?></option>
</select>
</font></td>
<td> </td>
</tr>
<tr>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'>Habitaciones</font></td>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'>Precio m&aacute;ximo:</font></td>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'>Tipo</font></td>
<td> </td>
</tr>
<tr>
<td> <font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<select name='envio4' size='1'>
<option value="-1"></option>
<?
$resultado4 = mysql_db_query($base,$pegar4)or die (mysql_error());
while ($registro4['Habitaciones'] = mysql_fetch_row($resultado4)){
foreach($registro4['Habitaciones'] as $clave4){
}
?>
<option><?

echo $clave4;
}

?></option>
</select>
</font></td>
<td> <font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<select name='envio5' size='1'>
<option value="-1"></option>
<option value="300">300€</option>
<option value="600">600€</option>
<option value="900">900€</option>
<option value="1200">1200€</option>
<option value="3000">3000€</option>
<option value="6000">6000€</option>
<option value="12000">12000€</option>
<option value="18000">18000€</option>
<option value="24000">24000€</option>
<option value="30000">30000€</option>
<option value="60000">60000€</option>
<option value="90000">90000€</option>
<option value="120000">120000€</option>
<option value="180000">180000€</option>
<option value="210000">210000€</option>
<option value="240000">240000€</option>
<option value="300000">300000€</option>

</select>
</font></td>
<td><font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<select name='envio3' size='1'>
<option value="-1"></option>
<?
$resultado3 = mysql_db_query($base,$pegar3)or die (mysql_error());
while ($registro3['Tipo'] = mysql_fetch_row($resultado3)){
foreach($registro3['Tipo'] as $clave3){
}
?>
<option><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFF00">
<?

echo $clave3;
}
?>
</font></option>
</select>
</font> </td>
<input type="hidden" value=<? echo $var1; ?> name="envio2">
<td><font face='Arial, Helvetica, sans-serif' size='1' color='#FFFF00'>
<input type='submit' name='Consultar' value='Consultar'>
</font></td>
</tr>
<tr>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'></font></td>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'></font></td>
<td><font face='Arial, Helvetica, sans-serif' size='1'

color='#FFFF00'></font></td>

<td> </td>
</tr>



</table>
</form>
</td>
</tr>

</table>
<?


mysql_close();

?>

Posted: Tue Mar 18, 2003 2:02 pm
by volka