<?php $query = $_GET['search-text'];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM movies WHERE (`title` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
} ?>
我没有在这里指定数据库连接。
我的HTML代码
<form id="frm-search" action="search.php" method="GET">
<div class="m-search">
<input type="hidden" id="search-text-value" name="search-text-value">
<input type="text" id="search-text" maxlength="150" class="search-text" name="search-text" placeholder="search" value="" autocomplete="off" onblur="" style="color: rgb(140, 140, 140);">
<input type="image" src="spray/search.png" value="" class="search-btn">
<div class="clear"></div>
</div>
</form>
它显示未定义的索引搜索文本和结果。当我尝试搜索时,它不会显示任何内容。
我在表格标签后回复它。
答案 0 :(得分:0)
做一些像echo $ results [index];在里面循环! 和 将SQL更改为:
mysql_query("SELECT * FROM movies WHERE title LIKE '$query%'");