Foros del Web » Programando para Internet » PHP »

mostrar todo con select dinamico

Estas en el tema de mostrar todo con select dinamico en el foro de PHP en Foros del Web. Hola, vengo con un nuevo problemita... Tengo 2 selects, uno que me indica un proyecto y el otro indica su estado: Primer select Código: PROYECTO ...
  #1 (permalink)  
Antiguo 27/02/2012, 13:06
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 14 años, 11 meses
Puntos: 0
mostrar todo con select dinamico

Hola, vengo con un nuevo problemita...

Tengo 2 selects, uno que me indica un proyecto y el otro indica su estado:

Primer select
Código:
PROYECTO    ID
proy1       1
proy2       2
proy3       3
.........
Segundo Select

Código:
ESTADO    ID
Todos     
Bueno     1
Regular   2
Malo      3
El filtrado funciona si le indico un proyecto y un estado, da igual cual, el problema que tengo es que no se que valor ponerle al ID del menu ESTADO en la opcion "todos" para que el WHERE muestre todas las filas de la tabla...
  #2 (permalink)  
Antiguo 27/02/2012, 13:15
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 20 años, 5 meses
Puntos: 50
Respuesta: mostrar todo con select dinamico

mandele un 99999 o un 0 y coloca la condicion del query en un condicional

Código PHP:
if ($dato != 999999)
$condicion = " where estado=".$dato;
else 
$condicion = " where estado in (1,2,3) "; // o ensu defecto no coloca condicion 
  #3 (permalink)  
Antiguo 27/02/2012, 14:16
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: mostrar todo con select dinamico

Mira, este es el codigo de mi pagina...

Código PHP:

<?php require_once('Connections/localhost.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;
}
}

mysql_select_db($database_localhost, $localhost);
$query_proyectos = "SELECT proy, noper FROM proyectos ORDER BY noper ASC";
$proyectos = mysql_query($query_proyectos, $localhost) or die(mysql_error());
$row_proyectos = mysql_fetch_assoc($proyectos);
$totalRows_proyectos = mysql_num_rows($proyectos);

mysql_select_db($database_formulario, $formulario);
$query_estados = "SELECT * FROM estado ORDER BY estado ASC";
$estados = mysql_query($query_estados, $formulario) or die(mysql_error());
$row_estados = mysql_fetch_assoc($estados);
$totalRows_estados = mysql_num_rows($estados);
?>
<!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>
<style type="text/css">
#form1 {
    text-align: center;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="get" action="proyecto_validado_elegido.php" target="down">
  <table width="650" border="0" align="center">
    <tr>
      <td width="644" align="center" valign="middle"><label for="noper"></label>
        <select name="noper" id="noper">
          <option value="">Seleccione un Proyecto...</option>
          <?php
do {  
?>
          <option value="<?php echo $row_proyectos['noper']?>"><?php echo $row_proyectos['proy']?> - <?php echo $row_proyectos['noper']; ?></option>
          <?php
} while ($row_proyectos = mysql_fetch_assoc($proyectos));
  
$rows = mysql_num_rows($proyectos);
  if(
$rows > 0) {
      
mysql_data_seek($proyectos, 0);
      
$row_proyectos = mysql_fetch_assoc($proyectos);
  }
?>
      </select></td>
    </tr>
    <tr>
      <td align="center" valign="middle"><label for="estados"></label>
        <select name="estados" id="estados">
          <option value="">Seleccione un Estado...</option>
          <option value="">TODOS</option>
          <?php
do {  
?>
<option value="<?php echo $row_estados['estado']?>"><?php echo $row_estados['estado']?></option>
          <?php
} while ($row_estados = mysql_fetch_assoc($estados));
  
$rows = mysql_num_rows($estados);
  if(
$rows > 0) {
      
mysql_data_seek($estados, 0);
      
$row_estados = mysql_fetch_assoc($estados);
  }
?>
      </select></td>
    </tr>
  </table>
  <input type="submit" name="enviar" id="enviar" value="Seleccionar" />
</form>
</body>
</html>
<?php
mysql_free_result
($proyectos);

mysql_free_result($estados);
?>

Etiquetas: dinamico, select, 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 05:02.