- >如何根据单词中的任何字母进行搜索,而不是根据我输入的每个字母和所有具有完全相同字母顺序的搜索进行搜索?
- >此外,我希望它在我输入内容时不向我显示所有查询,但仅在我开始输入后显示结果,因此它们更准确
- >最后一件事(对不起)如果我在搜索栏中键入内容然后将其删除,则会留下一些随机查询?帮助?
function searchq() {
var searchTxt = $("input[name='search']").val();
if($.trim(searchTxt) != '') {
$.post("search.php",{searchVal:searchTxt,}, function(output) {
$("#output").html(output);
});
}
}
if(isset($_POST['searchVal'])) {
$searchq = $_POST['searchVal'];
$searchq = preg_replace("/[^A-Za-z0-9_\ -]/","",$searchq);
$query = mysql_query("SELECT * FROM persons WHERE firstname LIKE '%$searchq%' OR lastname LIKE '%$searchq%' ") or die("Don't know why I could not search for you!");
$count = mysql_num_rows($query);
if($count == 0) {
$output = 'There Were NO Such Results!';
}else {
while($row = mysql_fetch_array($query)) {
$fname = $row['firstname'];
$lname = $row['lastname'];
$id = $row['id'];
$output .= '<div id="queryresult"><p><a href="#"> '.$fname.' </p></div>';
}
}
}
echo ($output);