Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/11/2012, 05:27
zuriKen
 
Fecha de Ingreso: noviembre-2012
Ubicación: Albatera
Mensajes: 1
Antigüedad: 11 años, 5 meses
Puntos: 0
Mensaje Búsqueda con sprintf y LIKE en la consulta

¡Hola!soy nuevo en esto ..tengo un problema y me gustaria saber si me podèis ayudar. Tengo una búsqueda para cuatro campos de una base de datos.Pero no cuando introduzco tildes o caracteres como guiones no daba error entonces intente usar la función sprintf con el LIKE en la consulta de la bùsqueda...pero me da erro que el spintf () no hay argumentos query vacío. La búsqueda la realizo $_POST["txtBusca"]..
El código es el siguiente..

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;
}//codigo que detecta el tipo y el valor de lo introducido ycrea función GetSQLValueString
//consulta de busqueda
$query_productos=sprintf("SELECT articulos.id,articulos.titulo,articulos.descripcio n,articulos.idioma,autores.nombre,articulos.imagen es,articulos.precio
FROM articulos,autores,escrito WHERE articulos.id=escrito.idarticulos AND escrito.idatores=autores.id AND disponible=1 AND (articulos.titulo LIKE '%s' OR articulos.descripcion LIKE '%s' OR articulos.idioma LIKE '%s' OR autores.nombre LIKE '%s')GROUP BY articulos.id,articulos.titulo,articulos.descripcio n,articulos.idioma,autores.nombre,articulos.imagen es,articulos.precio ORDER BY titulo ASC",GetSQLValueString(utf8_encode($_POST["txtBusca"]), "text"));