Foros del Web » Programando para Internet » PHP »

Busqueda por medio de combobox

Estas en el tema de Busqueda por medio de combobox en el foro de PHP en Foros del Web. Hola a todos los foreros, bueno mi duda es lo siguiente tengo un combobox con las secciones de las noticias de mi tabla, creado de ...
  #1 (permalink)  
Antiguo 05/10/2010, 11:43
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Busqueda por medio de combobox

Hola a todos los foreros, bueno mi duda es lo siguiente tengo un combobox con las secciones de las noticias de mi tabla, creado de la siguiente manera:

Código PHP:
<form name="form" action="noticias.php" method="post"><select name="busqueda">

 <option value="0">Ver Todas</option>
            <?php
            $ssql 
"select * from seccion";
            
$ql mysql_query($ssql,$conn) or die(mysql_error());
            while(
$g mysql_fetch_array($ql)){
            if(
$g['seccion'] == 'noticias de campeche'){
echo 
'<option value="'.$g['id_seccion'].'">Noticias De Campeche</option>';
}
if(
$g['seccion'] == 'espectaculos'){
echo 
'<option value="'.$g['id_seccion'].'">Espectáculos</option>';
}
if(
$g['seccion'] == 'deportes'){
echo 
'<option value="'.$g['id_seccion'].'">Deportes</option>';
}
if(
$g['seccion'] == 'mexico y el mundo'){
echo 
'<option value="'.$g['id_seccion'].'">México y El Mundo</option>';
}
if(
$g['seccion'] == 'reportajes'){
echo 
'<option value="'.$g['id_seccion'].'">Reportajes</option>';
}
if(
$g['seccion'] == 'mundo maya'){
echo 
'<option value="'.$g['id_seccion'].'">Mundo Maya</option>';
}
if(
$g['seccion'] == 'lo insolito'){
echo 
'<option value="'.$g['id_seccion'].'">Lo Insolito</option>';
}
if(
$g['seccion'] == 'eventos'){
echo 
'<option value="'.$g['id_seccion'].'">Eventos</option>';
}
if(
$g['seccion'] == 'opinion'){
echo 
'<option value="'.$g['id_seccion'].'">Opinión</option>';
}
            }
            
?>
            </select></form>
luego entonces quisiera modificar la consulta sql que tengo en mi pagina que es la misma donde esta el formulario con el combobox para poder mostrar los resultados segun la opcion que elijan, este en mi consulta:


Código PHP:
$sql "select * from noticias where mes = '$mes' and anio = '$ano' limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;        
                    
$result mysql_query($sql,$conn) or die(mysql_error()); 
gracias, por sus respuestas
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #2 (permalink)  
Antiguo 05/10/2010, 12:21
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Fácil, tienes que colocar en el where el valor que hayas seleccionada que te trae $_POST

$sql = "select * from noticias where mes = '$mes' and anio = '$ano' and seccion = ".$_POST['valor obtenido]." limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;

Observaciones

1) diagnostica primero $_POST porque tienes valor cero (0) para todas,
2) si quieres asígnas el valor a otra varibles por gusto,

Saludis
  #3 (permalink)  
Antiguo 05/10/2010, 12:23
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Disculpa $_POST['busqueda'] eso quiere decir que puede quedar así

$sql = "select * from noticias where mes = '$mes' and anio = '$ano' and seccion = ".$_POST['bisqueda']." limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;

  #4 (permalink)  
Antiguo 05/10/2010, 13:28
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

egepe gracias por tu respuesta he cambiado mi codigo a la siguiente forma:

Código PHP:
if($_POST['busqueda'] == 0){
                    
$sql "select * from noticias where mes = '$mes' and anio = '$ano' limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;    }
                    else{
                        
$sql "select * from noticias where mes = '$mes' and anio = '$ano' and seccion = ".$_POST['busqueda']." limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;} 
pero dejame decirte que marca el siguiente error:

Código HTML:
Notice: Undefined index: busqueda in C:\wamp\www\WEB\Sitio Web\admin\noticias.php on line 167
no me reconoce el select del form porque sucedera esto, gracias de antemano
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #5 (permalink)  
Antiguo 05/10/2010, 13:34
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Eso ocurre cuando una var no está definida, si quieres haz un echo de $_POST previo a esa consulta hazla así para que la veas mejor digo yo:

echo "<pre>";print_r($_POST);echo "</pre>";
para que puedas ver todos los datos q trae $_POST, exactemente para el caso de cuando seleccionas algún valor y me avisas
  #6 (permalink)  
Antiguo 05/10/2010, 14:04
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Cita:
Iniciado por egepe Ver Mensaje
Eso ocurre cuando una var no está definida, si quieres haz un echo de $_POST previo a esa consulta hazla así para que la veas mejor digo yo:

echo "<pre>";print_r($_POST);echo "</pre>";
para que puedas ver todos los datos q trae $_POST, exactemente para el caso de cuando seleccionas algún valor y me avisas

Me muestra lo siguiente en pantalla
Array
(
)
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #7 (permalink)  
Antiguo 05/10/2010, 14:15
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Para decirte que usaras $_POST y busqueda es porque vi que en el código que colocaste tu form usa el metodo POST y te coloque 'busqueda' porque vi q en el mismo codigo llamas al <select name="busqueda">. Ahora no sé si cambiaste alguno de ellos

verificalo porque no está recibiendo el $_POST

Saludos y me avisas
  #8 (permalink)  
Antiguo 05/10/2010, 14:17
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

no asi como postee en primera instancia mi form asi lo he dejado no he modificado nada de ahi,
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #9 (permalink)  
Antiguo 05/10/2010, 14:24
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Cita:
Iniciado por zapt142 Ver Mensaje
no asi como postee en primera instancia mi form asi lo he dejado no he modificado nada de ahi,
Pues yo acabo de probar tu codigo sacando la consulta a bd y me funciono????

No sé que puede estar ocurriendo en noticias.php q no te deja ver eso

Te dejo el codigo tuyo sin la busqueda de bd y cambian el action para que sea él mismo
Código PHP:
<?php

echo "<pre>";print_r($_POST);echo "</pre>";
?>
<form name="form" action="" method="post"><select name="busqueda">

 <option value="0">Ver Todas</option>
            <?php
            
echo '<option value="1">Noticias De Campeche</option>';
echo 
'<option value="2">Espectáculos</option>';
echo 
'<option value="3">Deportes</option>';
echo 
'<option value="4">México y El Mundo</option>';
echo 
'<option value="5">Reportajes</option>';
echo 
'<option value="6">Mundo Maya</option>';
echo 
'<option value="7">Lo Insolito</option>';
echo 
'<option value="8">Eventos</option>';
echo 
'<option value="9">Opinión</option>';

            
?>
            </select><input name="" type="submit" />
            
            </form>

Última edición por egepe; 05/10/2010 a las 14:33
  #10 (permalink)  
Antiguo 05/10/2010, 14:36
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

tendre que ver que la consulta la hago despues del form?

mira te muestro completo el archivo noticias.php

Código PHP:
Ver original
  1. $query = "select count(*) as suma from noticias where mes = '$mes' and anio = '$ano'";
  2.                       $res = mysql_query($query,$conn) or die(mysql_error());
  3.                       $fila = mysql_fetch_array($res);
  4.                       $filas_pagina = 15;
  5.                        $numpaginas = ceil($fila['suma']/$filas_pagina);
  6.  
  7. if(isset($_REQUEST['pagina']))
  8. {
  9.     $pagina=$_REQUEST['pagina'];
  10. }
  11. else
  12. {
  13.     $pagina = 1;
  14. }
  15.                    
  16.  
  17. ?>
  18. <html>
  19. <head>
  20. <title>Noticias</title>
  21. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  22. <style type="text/css">
  23. <!--
  24. body {
  25.     background-image: url(images/fondoadmin.jpg);
  26.     background-repeat: repeat-x;
  27. }
  28. -->
  29. </style>
  30. <link href="file:///C|/wamp/www/el faroadmin/text.css" rel="stylesheet" type="text/css">
  31. </script>
  32. </head>
  33. <body bgcolor="#EBEBDC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  34. <!-- ImageReady Slices (elfaro_administrador.psd) -->
  35. <table width="1100" height="210" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  36. <tr>
  37.         <td height="121" valign="top">
  38.             <img src="images/elfaro_administrador_01.jpg" width="1100" height="121" alt=""></td>
  39.   </tr>
  40.     <tr>
  41.         <td height="26" valign="top">
  42.             <img src="images/botonesmenu/btnsnoticias.jpg" width="1100" height="26" alt=""></td>
  43.   </tr>
  44.     <tr>
  45.         <td width="1100" height="44" valign="top"><table width="1097" border="0" cellpadding="0" cellspacing="0">
  46.           <tr>
  47.             <td width="63" height="7"></td>
  48.             <td width="840"></td>
  49.             <td width="194"></td>
  50.           </tr>
  51.           <tr>
  52.             <td>&nbsp;</td>
  53.             <td class="texttituloseccion">:: <span class="Tituloseccion">Noticias</span></td>
  54.             <td><!--BTN DE AGREGAR --><img src="images/botones/agregarmas.jpg" width="121" height="24"></td>
  55.           </tr>
  56.         </table></td>
  57.   </tr>
  58.     <tr>
  59.         <td height="19" valign="top"><table width="1099" border="0" cellpadding="0" cellspacing="0">
  60.           <tr>
  61.             <td>&nbsp;</td>
  62.             <td></td>
  63.             <td>&nbsp;</td>
  64.           </tr>
  65.           <tr>
  66.             <td>&nbsp;</td>
  67.             <td class="general">Filtrar por seccion Perteneciente: <form name="form" action="noticias.php" method="post"><select name="busqueda">
  68.  
  69.  <option value="0">Ver Todas</option>
  70.             <?php
  71.             $ssql = "select * from seccion";
  72.             $ql = mysql_query($ssql,$conn) or die(mysql_error());
  73.             while($g = mysql_fetch_array($ql)){
  74.             if($g['seccion'] == 'noticias de campeche'){
  75. echo '<option value="'.$g['id_seccion'].'">Noticias De Campeche</option>';
  76. }
  77. if($g['seccion'] == 'espectaculos'){
  78. echo '<option value="'.$g['id_seccion'].'">Espectáculos</option>';
  79. }
  80. if($g['seccion'] == 'deportes'){
  81. echo '<option value="'.$g['id_seccion'].'">Deportes</option>';
  82. }
  83. if($g['seccion'] == 'mexico y el mundo'){
  84. echo '<option value="'.$g['id_seccion'].'">México y El Mundo</option>';
  85. }
  86. if($g['seccion'] == 'reportajes'){
  87. echo '<option value="'.$g['id_seccion'].'">Reportajes</option>';
  88. }
  89. if($g['seccion'] == 'mundo maya'){
  90. echo '<option value="'.$g['id_seccion'].'">Mundo Maya</option>';
  91. }
  92. if($g['seccion'] == 'lo insolito'){
  93. echo '<option value="'.$g['id_seccion'].'">Lo Insolito</option>';
  94. }
  95. if($g['seccion'] == 'eventos'){
  96. echo '<option value="'.$g['id_seccion'].'">Eventos</option>';
  97. }
  98. if($g['seccion'] == 'opinion'){
  99. echo '<option value="'.$g['id_seccion'].'">Opinión</option>';
  100. }
  101.             }
  102.             ?>
  103.             </select></form></td>
  104.             <td>&nbsp;</td>
  105.           </tr>
  106.           <tr>
  107.             <td width="85" height="7"></td>
  108.             <td width="929"></td>
  109.             <td width="85"></td>
  110.           </tr>
  111.           <tr>
  112.             <td>&nbsp;</td>
  113.             <td><!--AQUI VAS A PONER TU INFO -->
  114.               <table width="928" height="49" border="0" cellpadding="0" cellspacing="0">
  115.                 <tr>
  116.                   <td><table width="929" border="0" cellpadding="0" cellspacing="1">
  117.                     <tr>
  118.                       <td width="19" bgcolor="dcedfd">&nbsp;</td>
  119.                       <td width="597" bgcolor="dcedfd" class="general">Selecione una noticia a editar</td>
  120.                       <td width="313" bgcolor="dcedfd" class="numerodetal"> &nbsp;Numero de Noticias Actuales:<?php            
  121.                       echo $fila['suma'];
  122.                       ?></td>
  123.                     </tr>
  124.                   </table></td>
  125.                 </tr>
  126.                 <tr>
  127.                   <td><table width="928" border="0" cellpadding="0" cellspacing="0">
  128.                     <tr>
  129.                       <td width="616" height="23" bgcolor="d8d8d8" class="titucolumnas"><div align="left">&nbsp;&nbsp;Nombre de Noticia</div></td>
  130.                       <td width="143" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Secci&oacute;n</div></td>
  131.                       <td width="96" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Publicada</div></td>
  132.                       <td width="73" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Eliminar</div></td>
  133.                     </tr>
  134.                     <?php
  135.                     echo "<pre>";print_r($_POST);echo "</pre>";
  136.                     //if($_POST['busqueda'] == 0){
  137.                     $sql = "select * from noticias where mes = '$mes' and anio = '$ano' limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;  //}
  138.                     /*else{
  139.                         $sql = "select * from noticias where mes = '$mes' and anio = '$ano' and seccion = ".$_POST['busqueda']." limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;}*/
  140.                     $result = mysql_query($sql,$conn) or die(mysql_error());
  141.                     while($row = mysql_fetch_array($result)){
  142.                     echo '<tr>';
  143.                     echo '<td><a href="edit_noticias.php?id_noticia='.$row['id_noticia'].'">'.$row['titulo'].'</a></td>';
  144.                     $do = "select * from seccion where id_seccion =".$row['seccion'];
  145.                     $done = mysql_query($do,$conn) or die(mysql_error());
  146.                     $a = mysql_fetch_array($done);
  147.                     if($a['seccion'] == 'noticias de campeche'){
  148. echo '<td align="center">Noticias De Campeche</td>';
  149. }
  150. if($a['seccion'] == 'espectaculos'){
  151. echo '<td align="center">Espectáculos</td>';
  152. }
  153. if($a['seccion'] == 'deportes'){
  154. echo '<td align="center">Deportes</td>';
  155. }
  156. if($a['seccion'] == 'mexico y el mundo'){
  157. echo '<td align="center">México y El Mundo</td>';
  158. }
  159. if($a['seccion'] == 'reportajes'){
  160. echo '<td align="center">Reportajes</td>';
  161. }
  162. if($a['seccion'] == 'mundo maya'){
  163. echo '<td align="center">Mundo Maya</td>';
  164. }
  165. if($a['seccion'] == 'lo insolito'){
  166. echo '<td align="center">Lo Insolito</td>';
  167. }
  168. if($a['seccion'] == 'eventos'){
  169. echo '<td align="center">Eventos</td>';
  170. }
  171. if($a['seccion'] == 'opinion'){
  172. echo '<td align="center">Opinión</td>';
  173. }
  174. echo '<td align="center">'.$row['publicada'].'</td>';
  175. echo '<td align="center"><a href="elim_noticia.php?id_noticia='.$row['id_noticia'].'"><img src="images/botones/eliminar.jpg" /></a></td>';
  176.                     echo '</tr>';
  177.                     }
  178.                     ?>
  179.                   </table>
  180.                   <?php
  181.                   echo '<table  cellspacing="3" height="50">';
  182. echo "<tr>";
  183.  
  184. if ($pagina!=1)
  185. {
  186. echo '<td class="nproduct"><strong><a href="noticias.php?pagina=1" style="color:#793f00; text-decoration:none"> << </a></strong></td>';
  187. echo '<td class="nproduct"><strong><a href="noticias.php?pagina='.($pagina-1).' "style="color:#793f00; text-decoration:none"> < </a></strong></td>';
  188. }
  189.  
  190. for($i=1;$i<=$numpaginas;$i++)
  191. {
  192.     $temp='';
  193.     if ($i==$pagina)
  194.         $temp=$i;
  195.     else
  196.         $temp='<a href="noticias.php?pagina='.$i.'" style="color:#000000; text-decoration:none">'.$i.'</a>';
  197.     echo '<td><strong>'.$temp.'</strong></td>'."\n";
  198. }
  199.  
  200. if ($pagina!=$numpaginas)
  201. {
  202.     echo '<td><strong><a href="noticias.php?pagina='.($pagina+1).'" style="color:#000000; text-decoration:none"> > </a></strong></td>';
  203.     echo '<td><strong><a href="noticias.php?pagina='.$numpaginas.'" style="color:#000000; text-decoration:none"> >> </a></strong></td>';
  204.  
  205. }
  206.  
  207. echo "</tr>";
  208. echo "</table>";
  209.  
  210.  
  211.                   ?></td>
  212.                 </tr>
  213.               </table></td>
  214.             <td>&nbsp;</td>
  215.           </tr>
  216.         </table></td>
  217.   </tr>
  218. </table>
  219. <!-- End ImageReady Slices -->
  220. </body>
  221. </html>

gracias de antemano
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #11 (permalink)  
Antiguo 05/10/2010, 14:50
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Este es tu codigo con los comentarios y a mi me funciona, ahora creo que te falta un boton de "submit" xq claro la primera vez $_POST no tiene nada, pero luego si le das al boton fijate que si muestra el valor.

Eso me hace pensar que tienes un problema en tu lógica
Saludos

Prueba este codigo que es el tuyo como te dije con comentarios y sin manejo de DB
Código PHP:
<?php 
/*
$query = "select count(*) as suma from noticias where mes = '$mes' and anio = '$ano'";
                      $res = mysql_query($query,$conn) or die(mysql_error());
                      $fila = mysql_fetch_array($res);
                      $filas_pagina = 15;
                       $numpaginas = ceil($fila['suma']/$filas_pagina);
 
if(isset($_REQUEST['pagina']))
{
    $pagina=$_REQUEST['pagina'];
}
else
{
    $pagina = 1;
}
                    
  */
?>
<html>
<head>
<title>Noticias</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {
    background-image: url(images/fondoadmin.jpg);
    background-repeat: repeat-x;
}
-->
</style>
<link href="file:///C|/wamp/www/el faroadmin/text.css" rel="stylesheet" type="text/css">
</script>
</head>
<body bgcolor="#EBEBDC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (elfaro_administrador.psd) -->
<table width="1100" height="210" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
        <td height="121" valign="top">
            <img src="images/elfaro_administrador_01.jpg" width="1100" height="121" alt=""></td>
  </tr>
    <tr>
        <td height="26" valign="top">
            <img src="images/botonesmenu/btnsnoticias.jpg" width="1100" height="26" alt=""></td>
  </tr>
    <tr>
        <td width="1100" height="44" valign="top"><table width="1097" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="63" height="7"></td>
            <td width="840"></td>
            <td width="194"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td class="texttituloseccion">:: <span class="Tituloseccion">Noticias</span></td>
            <td><!--BTN DE AGREGAR --><img src="images/botones/agregarmas.jpg" width="121" height="24"></td>
          </tr>
        </table></td>
  </tr>
    <tr>
        <td height="19" valign="top"><table width="1099" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>&nbsp;</td>
            <td></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td> 
            <td class="general">Filtrar por seccion Perteneciente: <form name="form" action="" method="post"><select name="busqueda">
 
 <option value="0">Ver Todas</option>
            <?php
            
echo '<option value="1">Noticias De Campeche</option>';
echo 
'<option value="2">Espectáculos</option>';
echo 
'<option value="3">Deportes</option>';
echo 
'<option value="4">México y El Mundo</option>';
echo 
'<option value="5">Reportajes</option>';
echo 
'<option value="6">Mundo Maya</option>';
echo 
'<option value="7">Lo Insolito</option>';
echo 
'<option value="8">Eventos</option>';
echo 
'<option value="9">Opinión</option>';
            
?>
            </select></select><input name="" type="submit" /></form></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td width="85" height="7"></td>
            <td width="929"></td>
            <td width="85"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><!--AQUI VAS A PONER TU INFO -->
              <table width="928" height="49" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td><table width="929" border="0" cellpadding="0" cellspacing="1">
                    <tr>
                      <td width="19" bgcolor="dcedfd">&nbsp;</td>
                      <td width="597" bgcolor="dcedfd" class="general">Selecione una noticia a editar</td>
                      <td width="313" bgcolor="dcedfd" class="numerodetal"> &nbsp;Numero de Noticias Actuales:<?php             
                     
// echo $fila['suma'];
                      
?></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td><table width="928" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="616" height="23" bgcolor="d8d8d8" class="titucolumnas"><div align="left">&nbsp;&nbsp;Nombre de Noticia</div></td>
                      <td width="143" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Secci&oacute;n</div></td>
                      <td width="96" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Publicada</div></td>
                      <td width="73" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Eliminar</div></td>
                    </tr>
                    <?php
                    
echo "<pre>";print_r($_POST);echo "</pre>";
                    
//if($_POST['busqueda'] == 0){
             //       $sql = "select * from noticias where mes = '$mes' and anio = '$ano' limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;  //}
                    /*else{
                        $sql = "select * from noticias where mes = '$mes' and anio = '$ano' and seccion = ".$_POST['busqueda']." limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;}*/
             /*       $result = mysql_query($sql,$conn) or die(mysql_error());
                    while($row = mysql_fetch_array($result)){
                    echo '<tr>';
                    echo '<td><a href="edit_noticias.php?id_noticia='.$row['id_noticia'].'">'.$row['titulo'].'</a></td>';
                    $do = "select * from seccion where id_seccion =".$row['seccion'];
                    $done = mysql_query($do,$conn) or die(mysql_error());
                    $a = mysql_fetch_array($done);
                    if($a['seccion'] == 'noticias de campeche'){
echo '<td align="center">Noticias De Campeche</td>';
}
if($a['seccion'] == 'espectaculos'){
echo '<td align="center">Espectáculos</td>';
}
if($a['seccion'] == 'deportes'){
echo '<td align="center">Deportes</td>';
}
if($a['seccion'] == 'mexico y el mundo'){
echo '<td align="center">México y El Mundo</td>';
}
if($a['seccion'] == 'reportajes'){
echo '<td align="center">Reportajes</td>';
}
if($a['seccion'] == 'mundo maya'){
echo '<td align="center">Mundo Maya</td>';
}
if($a['seccion'] == 'lo insolito'){
echo '<td align="center">Lo Insolito</td>';
}
if($a['seccion'] == 'eventos'){
echo '<td align="center">Eventos</td>';
}
if($a['seccion'] == 'opinion'){
echo '<td align="center">Opinión</td>';
}
echo '<td align="center">'.$row['publicada'].'</td>';
echo '<td align="center"><a href="elim_noticia.php?id_noticia='.$row['id_noticia'].'"><img src="images/botones/eliminar.jpg" /></a></td>';
                    echo '</tr>';
                    } */
                    
?>
                  </table>
                  <?php
/*
echo '<table  cellspacing="3" height="50">';
echo "<tr>";
 
if ($pagina!=1)
{
echo '<td class="nproduct"><strong><a href="noticias.php?pagina=1" style="color:#793f00; text-decoration:none"> << </a></strong></td>';
echo '<td class="nproduct"><strong><a href="noticias.php?pagina='.($pagina-1).' "style="color:#793f00; text-decoration:none"> < </a></strong></td>';
}
 
for($i=1;$i<=$numpaginas;$i++)
{
    $temp='';
    if ($i==$pagina)
        $temp=$i;
    else
        $temp='<a href="noticias.php?pagina='.$i.'" style="color:#000000; text-decoration:none">'.$i.'</a>';
    echo '<td><strong>'.$temp.'</strong></td>'."\n";
}
 
if ($pagina!=$numpaginas)
{
    echo '<td><strong><a href="noticias.php?pagina='.($pagina+1).'" style="color:#000000; text-decoration:none"> > </a></strong></td>';
    echo '<td><strong><a href="noticias.php?pagina='.$numpaginas.'" style="color:#000000; text-decoration:none"> >> </a></strong></td>';
 
}
 
echo "</tr>";
echo "</table>";
 
 
              */    
?></td>
                </tr>
              </table></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
  </tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
Te repito yo lo corrí y funciono perfecto, Ahora como te comente al principio $_POST no existe
  #12 (permalink)  
Antiguo 05/10/2010, 15:07
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

he modificado mi codigo del form, de tal forma que ya no necesito un boton del tipo submit para enviar el form sino que el evento onchange del combobox lo envie bueno aqui esta mi codigo:

Código PHP:
Ver original
  1. <?php
  2. include('config.php');
  3. $query = "select count(*) as suma from noticias where mes = '$mes' and anio = '$ano'";
  4.                       $res = mysql_query($query,$conn) or die(mysql_error());
  5.                       $fila = mysql_fetch_array($res);
  6.                       $filas_pagina = 15;
  7.                        $numpaginas = ceil($fila['suma']/$filas_pagina);
  8.  
  9. if(isset($_REQUEST['pagina']))
  10. {
  11.     $pagina=$_REQUEST['pagina'];
  12. }
  13. else
  14. {
  15.     $pagina = 1;
  16. }
  17.                     $sql = "select * from noticias where mes = '$mes' and anio = '$ano' limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;
  18.                                    
  19. ?>
  20. <html>
  21. <head>
  22. <title>Noticias</title>
  23. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  24. <style type="text/css">
  25. <!--
  26. body {
  27.     background-image: url(images/fondoadmin.jpg);
  28.     background-repeat: repeat-x;
  29. }
  30. -->
  31. </style>
  32. <link href="file:///C|/wamp/www/el faroadmin/text.css" rel="stylesheet" type="text/css">
  33. </script>
  34. </head>
  35. <body bgcolor="#EBEBDC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  36. <!-- ImageReady Slices (elfaro_administrador.psd) -->
  37. <table width="1100" height="210" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  38. <tr>
  39.         <td height="121" valign="top">
  40.             <img src="images/elfaro_administrador_01.jpg" width="1100" height="121" alt=""></td>
  41.   </tr>
  42.     <tr>
  43.         <td height="26" valign="top">
  44.             <img src="images/botonesmenu/btnsnoticias.jpg" width="1100" height="26" alt=""></td>
  45.   </tr>
  46.     <tr>
  47.         <td width="1100" height="44" valign="top"><table width="1097" border="0" cellpadding="0" cellspacing="0">
  48.           <tr>
  49.             <td width="63" height="7"></td>
  50.             <td width="840"></td>
  51.             <td width="194"></td>
  52.           </tr>
  53.           <tr>
  54.             <td>&nbsp;</td>
  55.             <td class="texttituloseccion">:: <span class="Tituloseccion">Noticias</span></td>
  56.             <td><!--BTN DE AGREGAR --><img src="images/botones/agregarmas.jpg" width="121" height="24"></td>
  57.           </tr>
  58.         </table></td>
  59.   </tr>
  60.     <tr>
  61.         <td height="19" valign="top"><table width="1099" border="0" cellpadding="0" cellspacing="0">
  62.           <tr>
  63.             <td>&nbsp;</td>
  64.             <td></td>
  65.             <td>&nbsp;</td>
  66.           </tr>
  67.           <tr>
  68.             <td>&nbsp;</td>
  69.             <td class="general">Filtrar por seccion Perteneciente: <form name="form" action="noticias.php" method="post"><select name="busqueda" onChange="form.submit();">
  70.  
  71.  <option value="100">Ver Todas</option>
  72.             <?php
  73.             $ssql = "select * from seccion";
  74.             $ql = mysql_query($ssql,$conn) or die(mysql_error());
  75.             while($g = mysql_fetch_array($ql)){
  76.             if($g['seccion'] == 'noticias de campeche'){
  77. echo '<option value="'.$g['id_seccion'].'">Noticias De Campeche</option>';
  78. }
  79. if($g['seccion'] == 'espectaculos'){
  80. echo '<option value="'.$g['id_seccion'].'">Espectáculos</option>';
  81. }
  82. if($g['seccion'] == 'deportes'){
  83. echo '<option value="'.$g['id_seccion'].'">Deportes</option>';
  84. }
  85. if($g['seccion'] == 'mexico y el mundo'){
  86. echo '<option value="'.$g['id_seccion'].'">México y El Mundo</option>';
  87. }
  88. if($g['seccion'] == 'reportajes'){
  89. echo '<option value="'.$g['id_seccion'].'">Reportajes</option>';
  90. }
  91. if($g['seccion'] == 'mundo maya'){
  92. echo '<option value="'.$g['id_seccion'].'">Mundo Maya</option>';
  93. }
  94. if($g['seccion'] == 'lo insolito'){
  95. echo '<option value="'.$g['id_seccion'].'">Lo Insolito</option>';
  96. }
  97. if($g['seccion'] == 'eventos'){
  98. echo '<option value="'.$g['id_seccion'].'">Eventos</option>';
  99. }
  100. if($g['seccion'] == 'opinion'){
  101. echo '<option value="'.$g['id_seccion'].'">Opinión</option>';
  102. }
  103.             }
  104.             ?>
  105.             </select>
  106.            <!-- <input type="submit" name="as" value="Ir" />-->
  107.             </form></td>
  108.             <td>&nbsp;</td>
  109.           </tr>
  110.           <tr>
  111.             <td width="85" height="7"></td>
  112.             <td width="929"></td>
  113.             <td width="85"></td>
  114.           </tr>
  115.           <tr>
  116.             <td>&nbsp;</td>
  117.             <td><!--AQUI VAS A PONER TU INFO -->
  118.               <table width="928" height="49" border="0" cellpadding="0" cellspacing="0">
  119.                 <tr>
  120.                   <td><table width="929" border="0" cellpadding="0" cellspacing="1">
  121.                     <tr>
  122.                       <td width="19" bgcolor="dcedfd">&nbsp;</td>
  123.                       <td width="597" bgcolor="dcedfd" class="general">Selecione una noticia a editar</td>
  124.                       <td width="313" bgcolor="dcedfd" class="numerodetal"> &nbsp;Numero de Noticias Actuales:<?php            
  125.                       echo $fila['suma'];
  126.                       ?></td>
  127.                     </tr>
  128.                   </table></td>
  129.                 </tr>
  130.                 <tr>
  131.                   <td><table width="928" border="0" cellpadding="0" cellspacing="0">
  132.                     <tr>
  133.                       <td width="616" height="23" bgcolor="d8d8d8" class="titucolumnas"><div align="left">&nbsp;&nbsp;Nombre de Noticia</div></td>
  134.                       <td width="143" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Secci&oacute;n</div></td>
  135.                       <td width="96" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Publicada</div></td>
  136.                       <td width="73" bgcolor="d8d8d8" class="titucolumnas"><div align="center">Eliminar</div></td>
  137.                     </tr>
  138.                     <?php
  139.                     if($_POST['busqueda'] == 100){
  140.                     $sql = "select * from noticias where mes = '$mes' and anio = '$ano' limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina; }
  141.                     if(($_POST['busqueda'] != 0) and ($_POST['busqueda'] != 100)){
  142.                     $query = "select count(*) as suma from noticias where mes = '$mes' and anio = '$ano' and seccion=".$_POST['busqueda'];
  143.                       $res = mysql_query($query,$conn) or die(mysql_error());
  144.                       $fila = mysql_fetch_array($res);
  145.                       $filas_pagina = 15;
  146.                        $numpaginas = ceil($fila['suma']/$filas_pagina);
  147.  
  148. if(isset($_REQUEST['pagina']))
  149. {
  150.     $pagina=$_REQUEST['pagina'];
  151. }
  152. else
  153. {
  154.     $pagina = 1;
  155. }
  156.                         $sql = "select * from noticias where mes = '$mes' and anio = '$ano' and seccion = ".$_POST['busqueda']." limit ".(($pagina-1)*$filas_pagina).",".$filas_pagina;
  157. }
  158.                     $result = mysql_query($sql,$conn) or die(mysql_error());
  159.                     while($row = mysql_fetch_array($result)){
  160.                     echo '<tr>';
  161.                     echo '<td><a href="edit_noticias.php?id_noticia='.$row['id_noticia'].'">'.$row['titulo'].'</a></td>';
  162.                     $do = "select * from seccion where id_seccion =".$row['seccion'];
  163.                     $done = mysql_query($do,$conn) or die(mysql_error());
  164.                     $a = mysql_fetch_array($done);
  165.                     if($a['seccion'] == 'noticias de campeche'){
  166. echo '<td align="center">Noticias De Campeche</td>';
  167. }
  168. if($a['seccion'] == 'espectaculos'){
  169. echo '<td align="center">Espectáculos</td>';
  170. }
  171. if($a['seccion'] == 'deportes'){
  172. echo '<td align="center">Deportes</td>';
  173. }
  174. if($a['seccion'] == 'mexico y el mundo'){
  175. echo '<td align="center">México y El Mundo</td>';
  176. }
  177. if($a['seccion'] == 'reportajes'){
  178. echo '<td align="center">Reportajes</td>';
  179. }
  180. if($a['seccion'] == 'mundo maya'){
  181. echo '<td align="center">Mundo Maya</td>';
  182. }
  183. if($a['seccion'] == 'lo insolito'){
  184. echo '<td align="center">Lo Insolito</td>';
  185. }
  186. if($a['seccion'] == 'eventos'){
  187. echo '<td align="center">Eventos</td>';
  188. }
  189. if($a['seccion'] == 'opinion'){
  190. echo '<td align="center">Opinión</td>';
  191. }
  192. echo '<td align="center">'.$row['publicada'].'</td>';
  193. echo '<td align="center"><a href="elim_noticia.php?id_noticia='.$row['id_noticia'].'"><img src="images/botones/eliminar.jpg" /></a></td>';
  194.                     echo '</tr>';
  195.                     }
  196.                     ?>
  197.                   </table>
  198.                   <?php
  199.                   echo '<table  cellspacing="3" height="50">';
  200. echo "<tr>";
  201.  
  202. if ($pagina!=1)
  203. {
  204. echo '<td class="nproduct"><strong><a href="noticias.php?pagina=1" style="color:#793f00; text-decoration:none"> << </a></strong></td>';
  205. echo '<td class="nproduct"><strong><a href="noticias.php?pagina='.($pagina-1).' "style="color:#793f00; text-decoration:none"> < </a></strong></td>';
  206. }
  207.  
  208. for($i=1;$i<=$numpaginas;$i++)
  209. {
  210.     $temp='';
  211.     if ($i==$pagina)
  212.         $temp=$i;
  213.     else
  214.         $temp='<a href="noticias.php?pagina='.$i.'" style="color:#000000; text-decoration:none">'.$i.'</a>';
  215.     echo '<td><strong>'.$temp.'</strong></td>'."\n";
  216. }
  217.  
  218. if ($pagina!=$numpaginas)
  219. {
  220.     echo '<td><strong><a href="noticias.php?pagina='.($pagina+1).'" style="color:#000000; text-decoration:none"> > </a></strong></td>';
  221.     echo '<td><strong><a href="noticias.php?pagina='.$numpaginas.'" style="color:#000000; text-decoration:none"> >> </a></strong></td>';
  222.  
  223. }
  224.  
  225. echo "</tr>";
  226. echo "</table>";
  227.  
  228.  
  229.                   ?></td>
  230.                 </tr>
  231.               </table></td>
  232.             <td>&nbsp;</td>
  233.           </tr>
  234.         </table></td>
  235.   </tr>
  236. </table>
  237. <!-- End ImageReady Slices -->
  238. </body>
  239. </html>

ahora mi duda es como hago para que me muestre todos otra vez ya que si elijo determinada sección funciona pero si elijo ver todas no me muestra todas,
gracias por tu tiempo, y tu orientación @egepe
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #13 (permalink)  
Antiguo 05/10/2010, 15:13
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Pregunto?

1) Y con el onchange te hace el submit y te pasa los valores al $_POST ?

Viendo tu codigo, pienso que quieres hacer algo como listas anidadas ya que pareciera que luego de selecionar el primero, bajas a otro select con unas opciones subordinadas al predecesor. Si eso es lo que quieres así, de verdad no es la mejor forma?

Saludos
  #14 (permalink)  
Antiguo 05/10/2010, 15:19
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

si me los pasa por el $_POST, y perdona por no explicarme bien pero no deseo hacer selects anidados las validaciones del if que tengo de esta manera:

Código PHP:
Ver original
  1. #
  2. if($g['seccion'] == 'espectaculos'){
son para cambiar el titulo de las noticas a mostrar en el select de busqueda ya que en la bd estan en minuscula y sin acento, ahora en mi codigo lleno una tabla con los datos de mi consulta pasandole como parametro el select de busqueda y como he mencionado antes me funciona si elijo una seccion determinada pero no asi si elijo la opcion Ver Todas.

Alguna idea, gracias
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #15 (permalink)  
Antiguo 05/10/2010, 15:37
Avatar de egepe  
Fecha de Ingreso: diciembre-2009
Mensajes: 310
Antigüedad: 14 años, 4 meses
Puntos: 7
Respuesta: Busqueda por medio de combobox

Lo primero no te lo entendí.

Lo segundo o último, recuerda que en tu <select> colocas value = 0 para "todas", por lo tanto en tu query tienes q quitar "seccion" para que te los traiga todos...


Etiquetas: combobox, medio, busquedas
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 09:14.