Php Can';当我点击建议时,不要选择它们
单击任何建议时,我无法选择它们 我希望这些建议可以点击,选择和改变颜色时,我对他们的悬停 我该怎么做 这是我当前的代码:Php Can';当我点击建议时,不要选择它们,php,html,css,search-suggestion,Php,Html,Css,Search Suggestion,单击任何建议时,我无法选择它们 我希望这些建议可以点击,选择和改变颜色时,我对他们的悬停 我该怎么做 这是我当前的代码: <?php include 'connect.php'; //connect with database $query = $_GET["q"]; if($query != "") { $safequery = mysqli_real_escape_string($con,$query); $stmt =
<?php
include 'connect.php'; //connect with database
$query = $_GET["q"];
if($query != "")
{
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . $safequery . "%' OR keywords LIKE '%" . $safequery . "%' OR link LIKE '%" . $safequery . "%' LIMIT 4";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$number_of_result = mysqli_num_rows($result);
if ($number_of_result > 0)
{
//results found here and display them
while ($row = \mysqli_fetch_assoc($result))
{ //show first 10 results
//add $title to an array which you will call json_encode(arr) on.
$title = $row["title"];
echo "<div id='sugg-search-result'>";
echo "<div id='sugg-title'>" . $title . "</div>";
echo "</div>";
}
}
}
?>
您可以尝试以下方法:
<?php
include 'connect.php'; //connect with database
$query = isset($_GET["q"]) ? $_GET : '' ;
if($query != "")
{
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . $safequery . "%' OR keywords LIKE '%" . $safequery . "%' OR link LIKE '%" . $safequery . "%' LIMIT 4";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$number_of_result = mysqli_num_rows($result);
if ($number_of_result > 0) {
//results found here and display them
while ($row = \mysqli_fetch_assoc($result)) { //show first 10 results
//add $title to an array which you will call json_encode(arr) on.
$title = $row["title"];
echo "<div id='sugg-search-result'>";
echo "<div class='suggestion' id='sugg-title'>" . $title . "</div>";
echo "</div>";
}
}
}
?>
您需要使用JavaScript和CSS。
基本示例:
// HTML Content
<style type="text/css">
#sugg-search-result {
width: 200px;
height: 150px;
/* ... */
}
#sugg-search-result .sugg-title {
height: 13px;
overflow: hidden;
/* ... */
}
#sugg-search-result .sugg-title:hover {
background: red;
cursor: pointer;
}
#sugg-search-result .sugg-title:active {
background: green;
}
</style>
//...
<?php
include 'connect.php'; //connect with database
$query = $_GET["q"];
if($query != "")
{
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . $safequery . "%' OR keywords LIKE '%" . $safequery . "%' OR link LIKE '%" . $safequery . "%' LIMIT 4";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
if (mysqli_num_rows($result) > 0)
{
echo '<div id="sugg-search-result">';
//results found here and display them
while( ($row = mysqli_fetch_assoc($result)) !== false )
{ //show first 10 results
//add $title to an array which you will call json_encode(arr) on.
$title = $row['title'];
echo '<div class="sugg-title" onclick="console.log(\'Make an action here\');">' , $title , '</div>';
}
echo '</div>';
}
}
?>
//HTML内容
#搜索结果{
宽度:200px;
高度:150像素;
/* ... */
}
#sugg搜索结果。sugg标题{
高度:13px;
溢出:隐藏;
/* ... */
}
#sugg搜索结果。sugg标题:悬停{
背景:红色;
光标:指针;
}
#sugg搜索结果。sugg标题:活动{
背景:绿色;
}
//...
关于鼠标悬停的效果,您可以考虑为sugg title css类制作一些css。例如,请参见jQuery的Autocomplete:及其相关样式表。你需要像Goikiu指出的那样用CSS做样式。您可以手动完成这一切,也可以只使用一些现成的解决方案,如Autocomplete或AutoSuggest(),自动提供必要的类和样式。
<!-- jQuery -->
<script>
$(document).on('click','.suggestion',function(){
// write your necessary javascript code
});
</script>
// HTML Content
<style type="text/css">
#sugg-search-result {
width: 200px;
height: 150px;
/* ... */
}
#sugg-search-result .sugg-title {
height: 13px;
overflow: hidden;
/* ... */
}
#sugg-search-result .sugg-title:hover {
background: red;
cursor: pointer;
}
#sugg-search-result .sugg-title:active {
background: green;
}
</style>
//...
<?php
include 'connect.php'; //connect with database
$query = $_GET["q"];
if($query != "")
{
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . $safequery . "%' OR keywords LIKE '%" . $safequery . "%' OR link LIKE '%" . $safequery . "%' LIMIT 4";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
if (mysqli_num_rows($result) > 0)
{
echo '<div id="sugg-search-result">';
//results found here and display them
while( ($row = mysqli_fetch_assoc($result)) !== false )
{ //show first 10 results
//add $title to an array which you will call json_encode(arr) on.
$title = $row['title'];
echo '<div class="sugg-title" onclick="console.log(\'Make an action here\');">' , $title , '</div>';
}
echo '</div>';
}
}
?>