Gente: estoy trabajando sobre un buscador, y quisiera que al elegir una marca, se procese el formu y me muestre los modelos:
Código:
<?
include ("conexion.php");
$conexion = mysql_connect ($host, $user, $pass);
mysql_select_db ($base, $conexion);
?>
<html>
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
|
</head>
<body>
<?php
function listar_modelos($marca)
{
echo "<select name=\"modelo\" id=\"modelo\">";
$sql_mod="SELECT distinct modelo FROM vehiculos where marca='$marca' order by modelo asc";
$result_mod = mysql_query($sql_mod, $conexion);
while ($row=mysql_fetch_array($result_mod))
{
echo $row['modelo'];
}
echo "</select>";
}
?>
<?php
if($Submit=="")
{?>
<form id="formulario">
<select name="marca" id="marca">
<?php
$sql_mar="SELECT * FROM marcas order by marca asc";
$result_mar = mysql_query($sql_mar, $conexion);
while ($row=mysql_fetch_array($result_mar))
{
?>
<option value="<?php echo $row['marca']; ?>"><?php echo $row['marca']; ?></option>
<?php
}
?>
</select>
<input type="submit" value="enviar" name="Submit"/>
</form>
<?php }
else
{
?>
<form id="formulario">
<select name="marca" id="marca">
<option value="<?php echo $marca ?>" selected="selected"><?php echo $marca; ?></option>
<?php
$sql_mar="SELECT * FROM marcas order by marca asc";
$result_mar = mysql_query($sql_mar, $conexion);
while ($row=mysql_fetch_array($result_mar))
{
?>
<option value="<?php echo $row['marca']; ?>"><?php echo $row['marca']; ?></option>
<?php
}
?>
</select>
<?php
echo listar_modelos($marca);
?>
<input type="submit" value="enviar" name="Submit"/>
</form>
<?php
}
?>
</body>
</html>
la consulta funciona perfectamente si la hago fuera, pero no logro que me devuelva los modelos, me devuelve el select vacío.
¿qué estoy haciendo mal?
gracias!