【发布时间】:2018-04-24 06:10:37
【问题描述】:
当我搜索query 时,我不想包含单词中的结果。
例如,如果我输入 "Place",我不想包含诸如 "Complacent" 这样的包含查询但不以查询开头的词。
有人可以建议一些可以阻止这种情况发生的代码吗?
$conn = mysqli_connect("localhost", "root", "", "movies");
$output = "";
if(isset($_POST['searchVal'])){
$searchq = $_POST['searchVal'];
$query = mysqli_query($conn, "SELECT * FROM movielist WHERE Kids LIKE 'True' AND (Name LIKE '%$searchq%' OR Description LIKE '%$searchq%' OR Year LIKE '%$searchq%' OR Genre LIKE '%$searchq%') ORDER BY Name") or die(mysqli_error());
$count = mysqli_num_rows($query);
if($count == 0){
$output = '<i>Nothing found</i>';
}
else {
while($row = mysqli_fetch_array($query)){
$id = $row['ID'];
$name = $row['Name'];
$description = $row['Description'];
$year = $row['Year'];
$link = $row['Link'];
$output .= '<p><a href="../player/?openMovie=' .$link. '"><b>' .$name. '</b><br><i>' .$description. ' - '.$year. '</i></a></p>';
}
}
}
echo($output);
?>
【问题讨论】: