Foros del Web » Programando para Internet » PHP »

como ver todas las filas de una tabla con select que filtra

Estas en el tema de como ver todas las filas de una tabla con select que filtra 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 24/02/2012, 13:31
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
como ver todas las filas de una tabla con select que filtra

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 de todos para que el WHERE de la funcion en mysql me muestre todas las filas...

por ejemplo, si elijo un proyecto y en el segundo pongo todos, me muestre todos los proyectos, independiente de si esta bueno, malo o regular...
  #2 (permalink)  
Antiguo 24/02/2012, 13:33
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: como ver todas las filas de una tabla con select que filtra

Este es el codigo de los select:

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']?></option>
          <?php
} while ($row_proyectos mysql_fetch_assoc($proyectos));
  
$rows mysql_num_rows($proyectos);
  if(
$rows 0) {
      
mysql_data_seek($proyectos0);
      
$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($estados0);
      
$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);
?>
  #3 (permalink)  
Antiguo 24/02/2012, 13:35
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: como ver todas las filas de una tabla con select que filtra

Y esta es la pagina que muestra los resultados:

Código PHP:
<?php require_once('Connections/localhost.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;
}
}

$currentPage $_SERVER["PHP_SELF"];

$maxRows_Recordset1 10;
$pageNum_Recordset1 0;
if (isset(
$_GET['pageNum_Recordset1'])) {
  
$pageNum_Recordset1 $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 $pageNum_Recordset1 $maxRows_Recordset1;

$colname_Recordset1 "-1";
if (isset(
$_GET['noper'])) {
  
$colname_Recordset1 $_GET['noper'];
}
$estados_Recordset1 "-1";
if (isset(
$_GET['estados'])) {
  
$estados_Recordset1 $_GET['estados'];
}
mysql_select_db($database_localhost$localhost);
$query_Recordset1 sprintf("SELECT ncert, Fecha, proyecto, poblacion, calle, n, tipo_recinto, n1, artefacto, estado, estanqueidad FROM cert_validado WHERE cod_proy = %s AND estado = %s ORDER BY ncert ASC"GetSQLValueString($colname_Recordset1"text"),GetSQLValueString($estados_Recordset1"text"));
$query_limit_Recordset1 sprintf("%s LIMIT %d, %d"$query_Recordset1$startRow_Recordset1$maxRows_Recordset1);
$Recordset1 mysql_query($query_limit_Recordset1$localhost) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);

if (isset(
$_GET['totalRows_Recordset1'])) {
  
$totalRows_Recordset1 $_GET['totalRows_Recordset1'];
} else {
  
$all_Recordset1 mysql_query($query_Recordset1);
  
$totalRows_Recordset1 mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_Recordset1") == false && 
        
stristr($param"totalRows_Recordset1") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_Recordset1 "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_Recordset1 sprintf("&totalRows_Recordset1=%d%s"$totalRows_Recordset1$queryString_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>
<style type="text/css">
<!--
 
TEXTAREA {
    background-color: #FFFFFF;
    border: black 1px solid;
    color: #000000;
    font-family: Arial;
    font-size: 10pt;
    font-weight: normal;


.Estilo1 {
    font-family: Arial;
    color: #000000;
    font-size: 12px;
    font-weight: bold;
}
.Estilo4 {
    font-family: Arial;
    color: #0000FF;
    font-size: 12px;
}
body {
    background-color: #FFFFFF;
}
.Estilo7 {
font-family: Arial;
font-size: 10px; 
}
-->
</style>
<script type="text/javascript">
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
</script>
</head>

<body>

  
</div></td>
<table width="950" border="0">
  <tr>
    <td width="87"><?php if ($pageNum_Recordset1 0) { // Show if not first page ?>
      <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPage0$queryString_Recordset1); ?>"><img src="imagenes/First.gif" alt="" /></a>
    <?php // Show if not first page ?></td>
    <td width="378"><?php if ($pageNum_Recordset1 0) { // Show if not first page ?>
      <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPagemax(0$pageNum_Recordset1 1), $queryString_Recordset1); ?>"><img src="imagenes/Previous.gif" alt="" /></a>
    <?php // Show if not first page ?></td>
    <td width="389" align="right"><?php if ($pageNum_Recordset1 $totalPages_Recordset1) { // Show if not last page ?>
      <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPagemin($totalPages_Recordset1$pageNum_Recordset1 1), $queryString_Recordset1); ?>"><img src="imagenes/Next.gif" alt="" /></a>
    <?php // Show if not last page ?></td>
    <td width="78" align="right"><?php if ($pageNum_Recordset1 $totalPages_Recordset1) { // Show if not last page ?>
      <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPage$totalPages_Recordset1$queryString_Recordset1); ?>"><img src="imagenes/Last.gif" alt="" /></a>
    <?php // Show if not last page ?></td>
  </tr>
</table>
<td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"></div></td>
<td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>>&nbsp;</td>
<td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>>&nbsp;</td>
<table width="950" border="0">
  <tr>
    <td colspan="13"><div align="center"><span class="Estilo7"><strong>Mantenci&oacute;n y Certificaci&oacute;n de Artefactos a Gas</strong></span>: <?php echo $row_Recordset1['proyecto']; ?></div></td>
  </tr>
  <tr>
    <td><div align="center" class="Estilo7"><strong>Nro. CERT.</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>FECHA</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>CALLE</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>Nro.</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>INSTALACION</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>Nro.</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>ARTEFACTO</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>ESTADO</strong></div></td>
    <td><div align="center" class="Estilo7"><strong>ESTANQUEIDAD</strong></div></td>
    <td colspan="2"><div align="center" class="Estilo7"><strong>DOC.</strong></div></td>
  </tr>
  <?php do { ?>
<tr onmouseover="this.style.backgroundColor='#E8E8E8'" onmouseout="this.style.backgroundColor='#ffffff'">
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['ncert']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['Fecha']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['calle']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['n']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['tipo_recinto']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['n1']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['artefacto']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7"><?php echo $row_Recordset1['estado']; ?></div></td>
    <td <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><div align="center" class="Estilo7">
      <div align="center" class="Estilo7"><?php echo $row_Recordset1['estanqueidad']; ?></div>
    </div></td>
    <td align="center" <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>><form action="#"  method="post" name="form1" id="form1" onsubmit="MM_openBrWindow('genera_certificado.php?numcert=<?php echo $row_Recordset1['ncert']; ?>','Certificado','scrollbars=yes,width=800,height=600')">
      <input type="submit" name="numcert" id="numcert" value="Ver" />
    </form></td>
    <td align="center" <?php //if ($c % 2 == 0) echo 'bgcolor="#E8E8E8"' ?>>
      <a href="#"><img src="botones/mail1.gif" alt="Email" name="numcert"  width="24" height="24" border="0" id="numcert" onclick="javascript:this.src='botones/mail2.gif';MM_openBrWindow('envia_correo.php?numcert=<?php echo $row_Recordset1['ncert']; ?>','','scrollbars=yes,width=400,height=300')" onmouseover="javascript:this.src='botones/mail2.gif'" onmouseout="javascript:this.src='botones/mail1.gif'" /></a>
      </td>
    </tr>
    <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
</table>
  #4 (permalink)  
Antiguo 24/02/2012, 13:35
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: como ver todas las filas de una tabla con select que filtra

Código PHP:

<table width="950" border="0">
  <tr>
    <td width="87"><?php if ($pageNum_Recordset1 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPage0$queryString_Recordset1); ?>"><img src="imagenes/First.gif" /></a>
      <?php // Show if not first page ?></td>
    <td width="378"><?php if ($pageNum_Recordset1 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPagemax(0$pageNum_Recordset1 1), $queryString_Recordset1); ?>"><img src="imagenes/Previous.gif" /></a>
      <?php // Show if not first page ?></td>
    <td width="389" align="right"><?php if ($pageNum_Recordset1 $totalPages_Recordset1) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPagemin($totalPages_Recordset1$pageNum_Recordset1 1), $queryString_Recordset1); ?>"><img src="imagenes/Next.gif" /></a>
      <?php // Show if not last page ?></td>
    <td width="78" align="right"><?php if ($pageNum_Recordset1 $totalPages_Recordset1) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s"$currentPage$totalPages_Recordset1$queryString_Recordset1); ?>"><img src="imagenes/Last.gif" /></a>
      <?php // Show if not last page ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>

Etiquetas: filas, mysql, select, tabla, todas
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 10:04.