我正在使用PHP,SQL和JqueryUI进行搜索,这是网址:http://digital-axioma.com.co/top100/
目前,用户可以查找名为“Nombre”的输入,但我需要用户可以查找名为“Nombre”的输入或称为“RazónSocial”的输入或称为“Ciudad”的输入。
这是代码:
<?php
class Conexion extends mysqli {
public function __construct(){
parent::__construct("localhost","root","","top");
$this->query("SET NAMES 'utf8';");
$this->connect_errno ? die("Error con la conexion") : $x = "Conectado";
unset($x);
}
/*The mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both.*/
public function recorrer($y){
return mysqli_fetch_array($y);
}
/* The mysqli_num_rows() function returns the number of rows in a result set */
public function rows($y){
return mysqli_num_rows($y);
}
}
?>
<?php
include("class.conection.php");
class Ajax {
public $buscador;
public function Buscar($a){
$db = new Conexion();
$this->buscador = $db->real_escape_string($a);
$sql = $db->query("SELECT * FROM top100seis WHERE Nombre LIKE '%$this->buscador%';");
while($array = $db->recorrer($sql)){
$resultado[] = $array["Nombre"];
}
return $resultado;
}
}
$busqueda = new Ajax();
echo json_encode($busqueda->Buscar($_GET["term"]));
?>
<aside id="buscador">
<div class="container">
<form method="GET" id="formulario-busqueda">
<div class="caja8">
<input type="text" name="buscar" id="buscar" placeholder="Buscar" />
</div>
<div class="caja2">
<button type="submit" id="boton-buscar"><i class="fa fa-search" aria-hidden="true"></i></button>
</div>
</form>
</div>
</aside>
答案 0 :(得分:-1)
在你的mysql中使用UNION
SELECT * FROM top100seis WHERE Nombre LIKE '%$this->buscador%'
UNION
SELECT * FROM top100seis WHERE Razón Social LIKE '%$this->buscador%'
UNION
SELECT * FROM top100seis WHERE Ciudad LIKE '%$this->buscador%'