Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/09/2009, 12:58
Avatar de spider_boy
spider_boy
 
Fecha de Ingreso: diciembre-2003
Ubicación: Chile
Mensajes: 1.855
Antigüedad: 20 años, 4 meses
Puntos: 89
Respuesta: generar consultas php a mysql con condicion de "si hay algo" o "si no" en

Debería ser así

Código html:
Ver original
  1. <form action="consultacompleta.php" method="post">
  2. <BR><BR><BR>
  3. <center>
  4. <tr>
  5. <td>Numero Folio</td>
  6. <td><input type='text' name='numero' maxlength='300' ></td></tr>
  7. <tr>
  8. <td>Clave Elector IFE</td>
  9.  
  10. <!-- ---------------------------------------------------------------------------------- -->
  11. <!-- En alguna parte debería ir este código, lo pongo acá porque no sé donde quieres ponerlo tú xD -->
  12.  
  13. <tr>
  14. <td> <input type="radio" name="condicion" value="1" /> Todos </td>
  15. </tr>
  16. <tr>
  17. <td> <input type="radio" name="condicion" value="2" /> Si </td>
  18. </tr>
  19. <tr>
  20. <td> <input type="radio" name="condicion" value="3" /> No </td>
  21. </tr>
  22. <!-- ---------------------------------------------------------------------------- -->
  23. <!-- ----------------------------------------------------------------------------- -->
  24.  
  25. <td><input type='text' name='ife' maxlength='300' ></td></tr>
  26. <TR>
  27. <TD><input type=SUBMIT name=BOTON2 value ="Consultar"></TD>
  28. <TD><input type=RESET name=BOTON1 value ="Borrar"></TD>
  29. </TR>
  30. </center>
  31.  
  32. </form>

Luego en el PHP, sería algo así :

Código php:
Ver original
  1. $condicion = $_POST['condicion'];
  2. $numero= $_POST['numero']
  3.  
  4. $consulta = "SELECT * FROM agenda";
  5. switch($condicion) {
  6.    case 1:
  7.       $consulta .= ""; // No agrega nada, por ende se ejecutara $consulta, mostrando todos los datos
  8.      break;
  9.    case 2:
  10.       $consulta .= " WHERE numero='".$numero."'"; // selecciono SI e introdujo un numero
  11.       break;
  12.   case 3:
  13.       $consulta .= " WHERE numero IS NULL"; // Selecciono NO, muestra los datos que no tienen numero
  14.      break;
  15. }
  16.  
  17. $sql = mysql_query($consulta) or die(mysql_error());
  18. while($row = mysql_fetch_array($sql))
  19. {
  20. echo
  21. "Numero= $row[numero] <br>
  22. Credencial Ife = $row[ife]<br>
  23. Nombre= $row[nombre]<br>"
  24. }

Creo que debería ser así. Disculpa si me equivoqué en algo.

Nos vemos.
__________________
Nunca te olvidaré mi negra hermosa. Te extraño demasiado.