Foros del Web » Programando para Internet » PHP »

Select en php + mysql

Estas en el tema de Select en php + mysql en el foro de PHP en Foros del Web. Hola, soy nuevo en el foro y en php, mi pregunta en la sgte En un campo de texto digito el num de textbox a ...
  #1 (permalink)  
Antiguo 21/11/2011, 15:47
 
Fecha de Ingreso: noviembre-2011
Mensajes: 27
Antigüedad: 12 años, 5 meses
Puntos: 0
Pregunta Select en php + mysql

Hola, soy nuevo en el foro y en php, mi pregunta en la sgte

En un campo de texto digito el num de textbox a generar y lo dirijo a otra pagina en la cual creo un for con el numero de datos a recibido previamente para generar los campos de texto. Debajo de esos campos de textos hay un select por cada textbox el cual recibe los datos de una bd.

El problema es que en el primer select me salen los datos correctamente pero a partir del segundo no me sale nada, si me pudieran ayudar se los agradeceria.

PD: anexo mi php

Código PHP:
<?php
require ("conexion.php");
$grado=$_REQUEST["grado"];
$cantidad=$_POST["c_materias"];
$consul_docente="SELECT * FROM docente";
$query=mysql_query($consul_docente,$con);
if(
mysql_num_rows($query)==0)
echo 
"Inserte Docentes";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nombre de Materias</title>
</head>
<body>
<h1 align="center">Nombre de Materias
</h1>
<p align="right"><a href="menu.php">Regresar al Menu</a> - <a href="cantidad_materia.php">Atras</a> - Salir</p>
<p align="center"><strong>Agregar Materias al grado:</strong> <?php echo $grado?> </p>
<form id="form1" name="form1" method="post" action="insertar_materia_nueva.php?curso=<?php echo $grado?>">
  <table width="90%" border="0" align="center">
   <?php
for($i=0;$i<$cantidad;$i++)
{
?>
    <tr>
      <td width="46%"><div align="right"><strong>Nombre:</strong></div></td>
      <td width="54%"><input type="text" name="nom_materia" id="nom_materia" /></td>
    </tr>
    <tr>
      <td><div align="right"><strong>Docente:</strong></div></td>
      <td>
      <select name="docente" id="docente">
        <option >Seleccione Docente</option>
<?php
 
while ($fila=mysql_fetch_array($query)){
echo 
"<option value='" .$fila['cedula'] ."'>" .$fila['nombre'] . " "$fila['apellido'] ." </option>";
 }
?>
      </select>
      <?php
}
      
mysql_close($con);
      
?>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="button" id="button" value="Enviar" /></td>
    </tr>
  </table>

</form>
<p align="center">&nbsp;</p>
</body>
</html>
saludos !!
espero que entiendan la pregunta alguna inquietud me dicen
  #2 (permalink)  
Antiguo 21/11/2011, 16:14
 
Fecha de Ingreso: mayo-2006
Mensajes: 475
Antigüedad: 18 años
Puntos: 58
Respuesta: Select en php + mysql

Prueba asi
Código PHP:
<?php
require ("conexion.php");
$grado=$_REQUEST["grado"];
$cantidad=$_POST["c_materias"];
$consul_docente="SELECT * FROM docente";
$query=mysql_query($consul_docente,$con);
if(
mysql_num_rows($query)==0)
echo 
"Inserte Docentes";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nombre de Materias</title>
</head>
<body>
<h1 align="center">Nombre de Materias
</h1>
<p align="right"><a href="menu.php">Regresar al Menu</a> - <a href="cantidad_materia.php">Atras</a> - Salir</p>
<p align="center"><strong>Agregar Materias al grado:</strong> <?php echo $grado?> </p>
<form id="form1" name="form1" method="post" action="insertar_materia_nueva.php?curso=<?php echo $grado?>">
  <table width="90%" border="0" align="center">
   <?php
for($i=0;$i<$cantidad;$i++)
{
?>
    <tr>
      <td width="46%"><div align="right"><strong>Nombre:</strong></div></td>
      <td width="54%"><input type="text" name="nom_materia" id="nom_materia" /></td>
    </tr>
    <tr>
      <td><div align="right"><strong>Docente:</strong></div></td>
      <td>
      <select name="docente" id="docente">
        <option >Seleccione Docente</option>
<?php
$consul_docente
="SELECT * FROM docente";
$query=mysql_query($consul_docente,$con);
 while (
$fila=mysql_fetch_array($query)){
echo 
"<option value='" .$fila['cedula'] ."'>" .$fila['nombre'] . " "$fila['apellido'] ." </option>";
 }
?>
      </select>
      <?php
}
      
mysql_close($con);
      
?>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="button" id="button" value="Enviar" /></td>
    </tr>
  </table>

</form>
<p align="center">&nbsp;</p>
</body>
</html>
  #3 (permalink)  
Antiguo 21/11/2011, 17:43
 
Fecha de Ingreso: noviembre-2011
Mensajes: 27
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: Select en php + mysql

si me funciono, gracias por tu ayuda. tengo una idea de cual era el problema pero me guistraia que tu me la dijeras para ver si es lo que pienso

gracoias de nuevo :)

Etiquetas: mysql, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:46.