我正在尝试在php中创建一个类似google的搜索框,但我不知道如何让它下拉而不是回显页面左上角的结果。
代码PHP:
$output = " ";
//collect
if(isset($_POST['searchbox'])){
$searchq = $_POST['searchbox'];
$query = DB::query("SELECT * FROM users WHERE username LIKE '%$searchq%'");
$count = count($searchq);
if(strlen($searchq) == 0 && $searchq!=$query){
$output .= "No such user";
echo $output;
}else{
foreach($query as $row){
$userq = $row['username'];
$output .= '<div style="position:relative;""><a href="profile.php?username='.$userq.'">'.$userq.'</a></div>';
echo $output;
}
}
}
代码html:
<input type="text" name="searchbox" class="search" placeholder="Search">
<input type="submit" value=">>">