Click to See Complete Forum and Search --> : Too tired to find the problem...


Perfidus
11-16-2003, 08:04 PM
I'm trying to feed a menu from database, from a table that have the fields Localidad, Localidad1, Localidad2, Localidad3, Localidad4. The criteria is to take them where Inmo=$Inmo.
What's wrong in this code?
Menu is empty!

<?
$base="";
$tabla="";
$conexion=mysql_connect("","","");
mysql_select_db($base,$conexion);
$pegar1 = "SELECT Localidad, Localidad1, Localidad2, Localidad3, Localidad4 FROM $tabla WHERE (Inmo='$Inmo')";
?>
<select name="Localidad" size="1" class="B">
<option value="-1"></option>
<?
$resultado1 = mysql_db_query($base,$pegar1)or die (mysql_error());
while ($registro['Localidad'] = mysql_fetch_row($resultado1))
{
foreach($registro['Localidad'] as $opciones){
}
?>
<option value=<? echo $opciones; ?>> <? echo $opciones;
}
?> </option>
</select>

Jona
11-16-2003, 08:29 PM
Try using mysql_fetch_assoc() instead of mysql_fetch_row(), or if you must use mysql_fetch_row() use mysql_fetch_row($resultadol, MYSQL_ASSOC)

That is, assuming you have your $conexion variable set properly (with the database, username and password, which I'm guessing you took out for obvious raesons).

[J]ona

-kde-
11-17-2003, 07:11 AM
Don't complicate your life :)


<?
mysql_connect("","","");
mysql_select_db($base);
$res = mysql_query("SELECT * FROM $tabla WHERE Inmo='$Inmo'");
?>
<select name="Localidad" size="1" class="B">
<option value="-1"></option>
<?
while ($data = mysql_fetch_array($res)) {
echo "<option value='{$data['opciones']}'>{$data['opciones']}</option>";
}
?>
</select>