Foros del Web » Programando para Internet » PHP »

Select con opcion de TODO

Estas en el tema de Select con opcion de TODO en el foro de PHP en Foros del Web. Hola chicos, necesito hacer algo, pero no se como... Tengo un Select Dinamico con el siguiente codigo: Código PHP: <?php  require_once( 'Connections/formulario.php' ); mysql_select_db ( ...
  #1 (permalink)  
Antiguo 10/09/2012, 09:59
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 11 años, 9 meses
Puntos: 0
Select con opcion de TODO

Hola chicos, necesito hacer algo, pero no se como...

Tengo un Select Dinamico con el siguiente codigo:

Código PHP:
<?php require_once('Connections/formulario.php');

mysql_select_db($database_formulario$formulario);
$query_Recordset1 "SELECT * FROM falla_calefon ORDER BY id ASC";
$Recordset1 mysql_query($query_Recordset1$formulario) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!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>Documento sin título</title>
</head>

<body>
<form id="form1" name="form1" method="get" action="prueba2.php">
  <select name="select" id="select">
    <option value="">Selecionar</option>
    <?php
do {  
?>
    <option value="<?php echo $row_Recordset1['id']?>"><?php echo $row_Recordset1['id']?></option>
    <?php
} while ($row_Recordset1 mysql_fetch_assoc($Recordset1));
  
$rows mysql_num_rows($Recordset1);
  if(
$rows 0) {
      
mysql_data_seek($Recordset10);
      
$row_Recordset1 mysql_fetch_assoc($Recordset1);
  }
?>
  </select>
  <input type="submit"/>
</form>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
en el cual, no tengo problemas para enviar lo que necesito a prueba2.php, la cual tiene el siguiente codigo

Código PHP:
<?php require_once('Connections/formulario.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$colname_Recordset1 "-1";
if (isset(
$_GET['select'])) {
  
$colname_Recordset1 $_GET['select'];
}
mysql_select_db($database_formulario$formulario);
$query_Recordset1 sprintf("SELECT * FROM falla_calefon WHERE id = %s"GetSQLValueString($colname_Recordset1"int"));
$Recordset1 mysql_query($query_Recordset1$formulario) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!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=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>
<table border="0">
  <tr>
    <td>id</td>
    <td>falla</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['id']; ?></td>
      <td><?php echo $row_Recordset1['falla']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
Ahora, lo que quiero, es que en el Select exista la opcion Todos, para poder ver todos los registros en la tabla de prueba2.php...

Como se hace???
  #2 (permalink)  
Antiguo 10/09/2012, 10:06
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 15 años, 11 meses
Puntos: 326
Respuesta: Select con opcion de TODO

Ains, cuanto daño hace DW!


Veamos, tu quieres esto:

Código HTML:
Ver original
  1. <select name="select" id="select">
  2.     <option value="">Seleccionar</option>
  3.     <option value="todos">Todos</option>
  4.     <option value="A">A</option>
  5.     <option value="B">B</option>

Q, viene a ser, un select básico en HTML... (Suponiendo q A y B son los valores de tu bbdd).

¿Cual es tu problema para añadir esta linea "<option value="todos">Todos</option>" al html? Sólo insertala manual, y listo!

Y con eso, en tu select tendrías la opción "todos"...

Pero, luego deberías tratar en el archivo prueba2.php con ese valor para que de la bbdd te pille "todos" y no solo uno.. ;)
__________________
>> Eleazan's Source
>> @Eleazan
  #3 (permalink)  
Antiguo 10/09/2012, 10:07
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 9 meses
Puntos: 2135
Respuesta: Select con opcion de TODO

Pues simplemente agrega una opción más a tu select:
Código HTML:
Ver original
  1. <option value="todo">Todo</option>

y en tu segunda pagina compruebas, si el valor de $_GET['select'] es igual a "todo" no limitas tu consulta, en caso contrario le agregas el WHERE.

Saludos.
  #4 (permalink)  
Antiguo 10/09/2012, 10:10
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Select con opcion de TODO

Cita:
Iniciado por GatorV Ver Mensaje

y en tu segunda pagina compruebas, si el valor de $_GET['select'] es igual a "todo" no limitas tu consulta, en caso contrario le agregas el WHERE.

Saludos.
Ese es mi problema, no se como realizar eso...
  #5 (permalink)  
Antiguo 10/09/2012, 10:19
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 9 meses
Puntos: 2135
Respuesta: Select con opcion de TODO

Con un simple if:
Código PHP:
Ver original
  1. // query sin la opción where
  2. $query = "SELECT * FROM foo";
  3. if ($miopcion != 'todo') { // si la opcion es diferente de todo agregas el where
  4.         $query .= " WHERE bar='$miopcion'";
  5. }

Etiquetas: formulario, html, mysql, opcion, registro, select, sql, tabla, todo
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 22:07.