同时在3行中进行实时搜索



如果每个用户有3行,我需要知道如何进行实时搜索才能找到完整的名称。。类似:

name,surename,lastname

Jhon-----erick--------doe

当我按照示例jhon doe或erick doe或jhon erick doo进行搜索时,会向我显示结果

jhon erick doe

这是我的实时搜索:

<?
$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: %sn", $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);
    }
}
?>

在页面中显示结果:

<div id="main">
<h4 id="results-text">Mostrando resultados para: <b id="search-string">Array</b></h4>
<ul id="results"></ul>
</div>

您可以创建这样的视图:

CREATE VIEW MyView as 
SELECT id_paciente,nombre,apellido,de_casada, nombre+' '+apellido+' '+de_casada as complete_name FROM PACIENTES 

然后在视图中进行查询:

SELECT id_paciente,nombre,apellido,de_casada,complete_name FROM MyView
WHERE id_paciente LIKE "%'.$search_string.'%" OR complete_name LIKE "%'.$search_string.'%" OR nombre LIKE "%'.$search_string.'%" OR apellido LIKE "%'.$search_string.'%" OR de_casada LIKE "%'.$search_string.'%"

相关内容

  • 没有找到相关文章

最新更新