Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/06/2011, 02:26
Avatar de totti026
totti026
 
Fecha de Ingreso: junio-2011
Mensajes: 150
Antigüedad: 12 años, 10 meses
Puntos: 4
Pregunta mysql_num_rows() y mysql_fetch_array()

Hola que tal. tengo un problema a la hora de una busqueda
cuando pulso el boton buscar me sale


mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Sistema\consultaresidentesisistemas.ph p on line 22

y

mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Sistema\consultaresidentesisistemas.ph p on line 139

y este mi codigo php
Código PHP:
Ver original
  1. <?php
  2. include("conexion.php");
  3. $busqueda = isset($_GET['busqueda']) ? $_GET['busqueda'] : null;
  4. $filtro = isset($_GET['busqueda']) ? $_GET['busqueda'] : null;
  5. $enlace = isset($_GET['busqueda']) ? $_GET['busqueda'] : null;
  6. $pagina = isset($_GET['num']) ? $_GET['num'] : null;
  7.  
  8. //===================== CREAMOS FILTRO DE BUSQUEDA =========================
  9. if ($busqueda!="") //Si se ha escrito algo para buscar
  10. {
  11.     if (is_string($busqueda))
  12.         $filtro = " and (nombre_residente like '%". $busqueda ."%' or correo_electronico=". $busqueda .")" ;
  13.     else
  14.         $filtro = " and (nombre_residente like '%". $busqueda ."%' or correo_electronico like '%". $busqueda ."%')" ;  
  15.     $enlace="<a href='consultaresidentesisistemas.php?num=1' title='Clic para ver todos los Residentes'>Mostrar todos</a>";
  16. }
  17.     //===================== FIN FILTRO DE BUSQUEDA =========================
  18.    
  19.     //Consultamos la tabla productos
  20. $list_campos=mysql_query("SELECT * FROM isistemas WHERE nombre_residente=nombre_residente ". $filtro ." ;",$conexion);
  21.     //Averiguamos cuantos registros devolvio la consulta anterior.
  22. $numero_reg=mysql_num_rows($list_campos);
  23.  
  24. //============== VERIFICAR RESULTADOS DE LA BUSQUEDA O CONSULTA ==================
  25. if ($numero_reg==0 && $busqueda=="")
  26. { //Si no buscamos nada y la consulta arroja CERO residentes, mostrar mensaje.
  27.    
  28.     echo '"Sin registros en la base de datos!<p><a href="ISistemas.php.php">Nuevo Residente</a></p>';
  29.     //exit();
  30. } elseif ($numero_reg==0){ //Mensaje para mostrar
  31.     $mensaje_registros="<font color='red'>No se han hallado registros con el criterio: <strong>". $busqueda ."</strong></font>";
  32. } elseif ($busqueda!=""){//MEnsaje para mostrar
  33.     $mensaje_registros="<font color='blue'>Registros hallados con el criterio '<strong>". $busqueda ."</strong>': ". $numero_reg ."</font>";
  34. } else {
  35.     $mensaje_registros="Registros en la base de datos: ". $numero_reg;
  36. }
  37. //============== FIN VERIFICAR RESULTADOS DE LA BUSQUEDA O CONSULTA ==================
  38. //============== GESTIONAR PAGINACION =============================
  39. //$numero_reg=mysql_num_rows($list_campos);
  40. $registros = 5;
  41. $pagina = $pagina;
  42.  
  43. if (!$pagina) {
  44.     $inicio = 0;
  45.     $pagina = 1;
  46. }
  47. else {
  48.     $inicio = ($pagina - 1) * $registros;
  49. }
  50. //============== FIN PAGINACION =============================
  51.  
  52. //Consulta con limit que permite paginar
  53. $fila_campos=mysql_query("SELECT * FROM isistemas WHERE nombre_residente=nombre_residente ". $filtro ." LIMIT $inicio,$registros;",$conexion);
  54. $total_paginas = ceil($numero_reg / $registros);
  55.  
  56. ?>
  57. <html>
  58. <head>
  59. <title>Consulta</title>
  60. <style type="text/css">
  61. .ms-simple1-main {
  62.     border-left-style: none;
  63.     border-right-style: none;
  64.     border-top: 1.5pt solid green;
  65.     border-bottom: 1.5pt solid green;
  66. }
  67. .ms-simple1-tl {
  68.     border-left-style: none;
  69.     border-right-style: none;
  70.     border-top-style: none;
  71.     border-bottom: .75pt solid green;
  72. }
  73. .ms-simple1-top {
  74.     border-left-style: none;
  75.     border-right-style: none;
  76.     border-top-style: none;
  77.     border-bottom: .75pt solid green;
  78. }
  79.  
  80. *
  81. {
  82. padding: 0em;
  83. margin: 0em;
  84. }
  85.  
  86. *
  87. {
  88. padding: 0em;
  89. margin: 0em;
  90. }
  91.  
  92. .auto-style7 {
  93.     text-align: right;
  94. }
  95.  
  96. .auto-style8 {
  97.     font-family: Aharoni;
  98.     font-size: medium;
  99.     color: #00FF00;
  100. }
  101.  
  102. .auto-style9 {
  103.     font-family: Aharoni;
  104. }
  105.  
  106. </style>
  107. </head>
  108.  
  109. <body>
  110. <div class="auto-style7">
  111. <br>
  112. <a href="menu2.php">Atras</a><br>
  113. </div>
  114. <form method="GET" action="consultaresidentesisistemas.php?num=1">
  115.     <span class="auto-style8">&nbsp;&nbsp;&nbsp;&nbsp; Buscar</span>&nbsp;
  116.  <input name="busqueda" type="text" id="busqueda" style="width: 209px" value="<?php echo $busqueda;?>">&nbsp;&nbsp;&nbsp;  
  117.     <input name="btnbuscar" type="submit" id="btnbuscar" value="Buscar" class="auto-style9">&nbsp;&nbsp;&nbsp;
  118.         <span><?php echo $enlace; ?></span><span><?php echo $mensaje_registros ?></span><br>
  119.     <br><hr><br></form><br>
  120. <center>
  121. <table border="0" cellspacing="0" style="width: 100%">
  122.         <tr>
  123.           <th width="150"   ><div align="center" >Nombre Residente</div></th>
  124.           <th width="50"  ><div align="center" >Correo Electronico</div></th>
  125.           <th width="100"  ><div align="center" >Telefono</div></th>
  126.           <th width="100"  ><div align="center" >Nombre del Proyecto</div></th>
  127.           <th width="150"  ><div align="center" >Asesor P/ Residencias</div></th>
  128.           <th width="150"  ><div align="center" >Revisor de Informe Tecnico</div></th>
  129.           <th width="100"  ><div align="center" >Fecha Inicio</div></th>
  130.           <th width="100"  ><div align="center" >Fecha Termino</div></th>
  131.           <th width="100"  ><div align="center" >Fecha Examen</div></th>
  132.           <th width="50"  ><div align="center" >Modificar</div></th>
  133.           <th width="50" ><div align="center" >Eliminar</div></th>
  134.         </tr>
  135.         <?php
  136.    
  137.    
  138.     $color="#E0E0E0";
  139.     while ($fila=mysql_fetch_array($fila_campos))
  140.     {
  141.         if ($color=="#FFFFCC") //claro
  142.             $color="#FFFF9F";
  143.         else
  144.             $color="#FFFFCC";
  145.     ?>
  146.         <tr bgcolor="<?php echo $color; ?>">
  147.           <td>
  148.             <div align="center"><?php  echo $fila["nombre_residente"]; ?></div></td>
  149.           <td>
  150.           <div align="center"><?php  echo $fila["correo_electronico"]; ?></div></td>
  151.           <td>
  152.           <div align="center"><?php  echo $fila["telefono"]; ?></div></td>
  153.           <td>
  154.           <div align="center"><?php  echo $fila["nombre_proyecto"]; ?></div></td>
  155.           <td>
  156.           <div align="center"><?php  echo $fila["asesor"]; ?></div></td>
  157.           <td>
  158.           <div align="center"><?php  echo $fila["revisor"]; ?></div></td>
  159.           <td>
  160.           <div align="center"><?php  echo $fila["fecha_inicio"]; ?></div></td>
  161.           <td>
  162.           <div align="center"><?php  echo $fila["fecha_termino"]; ?></div></td>
  163.           <td>
  164.           <div align="center"><?php  echo $fila["fecha_examen"]; ?></div></td>
  165.           <td><div align="center"><a onClick="window.open('modificarISistemas.php?nomres=<?php echo $fila["nombre_residente"]; ?>&num=<?php echo $_GET["num"]; ?>','Modificar','width=850,height=600,left=250,top=100,menubar=1,toolbar=1,resizable=0,resizable=no,scrollbars=0,scrollbars=yes')" href="javascript:void(0);">Modificar</a></div></td>
  166.           <td><div align="center"><a href="confirmaeliminaresidente.php?nomres=<?php  echo $fila["nombre_residente"]; ?>&num=<?php echo $_GET["num"]; ?>" title="Clic para eliminar <?php echo $fila["nombre_residente"]; ?>">Eliminar</a></div></td>
  167.         </tr>
  168.         <?php
  169.     }
  170.     ?>
  171.        
  172.       </table><?php
  173.  
  174.     //Pagina Anterior
  175.     if(($pagina - 1) > 0) {
  176.         echo "<a href='consultaresidentesisistemas.php?num=".($pagina-1)."'>< Anterior</a> ";
  177.         }
  178.     //Listado de paginas
  179.     if ($total_paginas>1)
  180.     {
  181.         for ($i=1; $i<=$total_paginas; $i++){
  182.             if ($pagina == $i) {
  183.                 echo "<b><font color='#FF0000' size='3'>".$pagina."</font></b> ";
  184.             } else {
  185.                 echo "<a href='consultaresidentesisistemas.php?num=$i'>$i</a> ";
  186.             }
  187.         }
  188.     }
  189.     //Pgina Siguiente
  190.     if(($pagina + 1)<=$total_paginas) {
  191.         echo " <a href='consultaresidentesisistemas.php?num=".($pagina+1)."'>Siguiente ></a>";
  192.     }
  193.  
  194. ?>
  195. </center>
  196. </body>
  197. </html>

No se donde tengo el error, tengo semanas tratando lo corregirlo y nada, alguna orientacion? o algun codigo que me permita realizar una busqueda por medio de una cadena de caracteres?. Muchas gracias masters