Re: Re: Pasar de SELECT a formulario
| From: | Alphacom | Date: | Sat, 03 May 2003 10:28:35 +0000 |
| Subject: | Re: Re: Pasar de SELECT a formulario | ||
| References: | 1 2 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-35792@lists.php.net to get a copy of this message | ||
Buenas me constesto yo mismo por si a alguién le puede interesar.
Aquí paso el código, el problema que me da es que me repite todos los valores,
alguien sabe porque?Supongo que el problema es del array pero...
<?php
//FUNCIÓN PARA GENERAR UN DESPLEGABLE DESDE UNA ARRAY
//
//The $options variable is an array where the key is the value
//of the option and the value is the displayed part of the option.
//
//The $selected variable is the item you want preselected and must
//match the value.
//
//The $var is the name of the option which will also be your
//variable in the script that uses your form data.
//Randall Augustus Alexander
//zonezero@zonedzero.net
//http://www.zonedzero.net ,.com, .org
function make_option($options, $selected = "", $var)
{
echo "<SELECT NAME='$var'>\n";
while (list ($value, $display) = each ($options))
{
echo "<OPTION VALUE='$value' ";
if ($value == $selected){$select = "SELECTED";}
else {$select = "";}
echo " $select>$display</OPTION>\n";
}
echo "</SELECT>\n";
}
//PREPARAR ARRAYS
$handle=mysql_connect('IP','user','pass');
echo "<head> <title> ACCESO ALUMNOS</title></head>";
$Display_Week_Day = '1';
if (!mysql_select_db("db_name"))
{
echo "No encuentro la base de datos";
exit;
}
$numeroal="0000000";
$comando="SELECT * from artic where numero='$numeroal'";
$r=mysql_query($comando) or die("Consulta Invalida");
$row=mysql_fetch_array($r);
//GENERA EL SELECT
echo "<html>
<head>
<title>Your Title</title>
</head>";
echo "<FORM ACTION='action.php' METHOD='post'>\n";
make_option($row, "", codigo);
echo "<p></p><INPUT TYPE='Submit' NAME='Submit'>\n";
echo "<p>$selected - $var \n";
echo "</html>";
?>
"Esteban F." wrote:
> Eso se hace c on Javascript, es una de las cualidades de generar contenido
> "on fly", te recomiendo busques informacion con respecto a eso
> especificamente.
>
> Saludos
> Esteban.
>
> "Alphacom" <webmaster@alphacom.es> escribió en el mensaje
> news:3EB24A2E.AABFF4EC@alphacom.es...
> > Hola lister@s,
> >
> > me han pedido que haga un formulario donde aparezca un select, y dentro
> > de este aprezcan unas opciones previamente buscadas dentro de un base
> > de datos. La base de datos de donde tengo que obtener lo que ira dentro
> > del select (del formulario) sería de este estilo:
> >
> > Codigo OP1 OP2 OP3 OP4 ...
> > kk * *
> > kk2 * *
> >
> > Donde el asterisco indica que si que cumple esa opción.
> >
> > Por lo que cuando en el formulario se introduzca kk aparecera un
> > desplegable con las opciones OP1 y OP2. Tal y como me quieren pasar la
> > BBDD se podría hacer??
> >
> > Gracias
> >
>
> ---------------------------------------------------------------------
> Archivo On-line: http://www.phpes.com/
> via news: news://news.phpes.com/
> Manual PHP en español: http://www.php.net/manual/es/
> Para dar de baja la suscripción, mande un mensaje a:
> lista-unsubscribe@phpes.com