I need to know how can I make my live search to work finding the complete name if I have 3 rows for every user..like:
table pacientes
name, surename, lastname
Jhon-----erick--------doe
and when I make the search per example jhon doe or erick doe or jhon erick doe show me the results
jhon erick doe
here is my live search:
<?
$dbhost = "localhost";
$dbname = "";
$dbuser = "";
$dbpass = "";
global $db;
$db = new mysqli();
$db->connect($dbhost, $dbuser, $dbpass, $dbname);
$db->set_charset("utf8");
if ($db->connect_errno) {
printf("Connect failed: %s\n", $db->connect_error);
exit();
}
$html = '';
$html .= '<li class="result">';
$html .= '<a target="_self" href="urlString">';
$html .= '<h3>nombreString apellidoString de_casadaString</h3>';
$html .= '<h4>Expediente # : id_pacienteString</h4>';
$html .= '</a>';
$html .= '</li>';
$search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
$search_string = $db->real_escape_string($search_string);
if (strlen($search_string) >= 1 && $search_string !== ' ') {
$query = 'SELECT id_paciente,nombre,apellido,de_casada FROM PACIENTES WHERE id_paciente LIKE "%'.$search_string.'%" OR nombre LIKE "%'.$search_string.'%" OR apellido LIKE "%'.$search_string.'%" OR de_casada LIKE "%'.$search_string.'%"';
$result = $db->query($query);
while($results = $result->fetch_array()) {
$result_array[] = $results;
}
if (isset($result_array)) {
foreach ($result_array as $result) {
$display_id_paciente = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['id_paciente']);
$display_name = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['nombre']);
$display_apell = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['apellido']);
$display_casada = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['de_casada']);
$display_url = 'paciente_personal_profile.php?id_paciente='.urlencode($result['id_paciente']);
$output = str_replace('nombreString', $display_name, $html);
$output = str_replace('apellidoString', $display_apell, $output);
$output = str_replace('de_casadaString', $display_casada, $output);
$output = str_replace('id_pacienteString', $display_id_paciente, $output);
$output = str_replace('urlString', $display_url, $output);
echo($output);
}
}else{
$output = str_replace('urlString', 'javascript:void(0);', $html);
$output = str_replace('nombreString apellidoString de_casadaString', '<b>Sin coincidencias.</b>', $output);
$output = str_replace('id_pacienteString', 'No hay expediente', $output);
echo($output);
}
}
?>
in the page show the result:
<div id="main">
<h4 id="results-text">Mostrando resultados para: <b id="search-string">Array</b></h4>
<ul id="results"></ul>
</div>