我有一个搜索栏和一个包含3部电影的SQL数据库
Name:Star Wars: Description: Contains the word group
Name:301: Description: Contains the word group
Name:destroyer: Description: Contains the word group
但是,当我搜索单词" group"
时我通常只得到一个结果:
这是我的PHP代码:
if(!isset($_POST['search']))
{
header("Location:index.php");
}
$search_sql="SELECT * FROM php_item WHERE Name LIKE '%".$_POST['search']."%' OR Description LIKE '%".$_POST['search']."%'";
$search_query = mysql_query($search_sql);
if(mysql_num_rows($search_query)!=0)
{
$search_rs= mysql_fetch_assoc($search_query);
}
?>
</p>
<p> Search Results</p>
<?php
if(mysql_num_rows($search_query) != 0){
do{ ?>
<p>
<?php echo $search_rs['Name']; ?>
<?php }while($searchr_rs=mysql_fetch_assoc($search_query));
} else {
echo "No Results Found";
}
?>
答案 0 :(得分:0)
EDIT 在我的旧帖子&amp;中将$ search_rs更改为$ searchr_rs;现在它会起作用
<?php
if(!isset($_POST['search']))
{
header("Location:index.php");
}
$search_sql="SELECT * FROM php_item WHERE Name LIKE '%".$_POST["search"]."%' OR Description LIKE '%".$_POST["search"]."%' ";
$search_query = mysql_query($search_sql);
//print_r($search_query);
if(!$search_query){
die(mysql_error());
}
if(mysql_num_rows($search_query)>0)
{
echo '<p> Search Results</p>';
while($searchr_rs=mysql_fetch_array($search_query))
{
echo ' <p>';
echo $searchr_rs['Name'];
echo '</p>';
}
} else {
echo "No Results Found";
}
?>