Ver Mensaje Individual
  #10 (permalink)  
Antiguo 15/07/2010, 15:43
rafaxusirati
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 13 años, 9 meses
Puntos: 4
Respuesta: Código PHP consulta múltiple a BD

Hola, buenas noches / días.
Finalmente monté este código, funciona correctamente en la busqueda de palabras de un mismo campo, pero, todavía no encuentro la manera de hacer una búsqueda múltiple en distintos campos.

Gracias.


Código PHP:
Ver original
  1. <?php require_once('Connections/contactos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $var1_obtenerCita = "-1";
  35. if (isset($_POST["terminoBusca"])) {
  36.   $var1_obtenerCita = $_POST["terminoBusca"];
  37. }
  38. mysql_select_db($database_contactos, $contactos);
  39. $query_obtenerCita = sprintf("SELECT * FROM contactos WHERE contactos.descripcionanuncio LIKE %s ORDER BY contactos.descripcionanuncio ", GetSQLValueString("%" . $var1_obtenerCita . "%", "text"));
  40. $obtenerCita = mysql_query($query_obtenerCita, $contactos) or die(mysql_error());
  41. $row_obtenerCita = mysql_fetch_assoc($obtenerCita);
  42. $totalRows_obtenerCita = mysql_num_rows($obtenerCita);$var1_obtenerCita = "-1";
  43. if (isset($_POST["terminoBusca"])) {
  44.   $var1_obtenerCita = $_POST["terminoBusca"];
  45. }
  46. mysql_select_db($database_contactos, $contactos);
  47. $query_obtenerCita = sprintf("SELECT * FROM contactos WHERE contactos.descripcionanuncio LIKE %s ORDER BY contactos.fechaentrada DESC ", GetSQLValueString("%" . $var1_obtenerCita . "%", "text"));
  48. $obtenerCita = mysql_query($query_obtenerCita, $contactos) or die(mysql_error());
  49. $row_obtenerCita = mysql_fetch_assoc($obtenerCita);
  50. $totalRows_obtenerCita = mysql_num_rows($obtenerCita);
  51. ?>
  52. <body>
  53. <form id="form1" name="form1" method="post" action="">
  54.   <label>Palabras clave:
  55.     <input type="text" name="terminoBusca" id="terminoBusca" />
  56.   </label>
  57.   <input type="submit" name="Buscar" id="Buscar" value="Buscar" />
  58. <strong><a href="buscar por palabra clave.php"></a></strong><strong><a href="buscar por palabra clave.php"></a></strong>
  59. </form>
  60. <?php do { ?>
  61. <a href="fichas_comentarios.php?idempleado=<?php echo $row_obtenerCita['idempleado']; ?>"><?php echo ucfirst($row_obtenerCita['tituloanuncio']); ?></a>
  62. <p>
  63.   <?php } while ($row_obtenerCita = mysql_fetch_assoc($obtenerCita)); ?>
  64.     <a href="fichas_comentarios.php?idempleado=<?php echo $row_obtenerCita['idempleado']; ?>"></a>
  65.   </p>
  66. <p>&nbsp;</p>
  67. <p align="center">&nbsp;</p>
  68. <p align="center">&nbsp;</p>
  69. </body>
  70. </html>
  71. <?php
  72. mysql_free_result($obtenerCita);
  73. ?>