php 模糊查询

2024-12-19 15:11:07
推荐回答(3个)
回答1:

你早就return了,还怎么得到结果,修改一下return的位置应该可以解决吧!如下:
function search($key){
$this->searcher = "select * from book where name like '%$key%'";
$result = mysql_query($this->searcher);

$num = mysql_num_rows($result);

for($i = 0;$i<$num;$i++)
{
$arr=mysql_fetch_array($result);
echo str_replace($key,"".$key."",$arr[name])."
";
}

return $result;
}

回答2:

输出 $this->searcher 看看 应该是你的sql 语法错误 建议写成这样

"select * from book where name like '%“.$key.”%'";

回答3:

function search($key){
$this->searcher = "select * from book where name like "."%$key%";
$result = mysql_query($this->searcher);
return $result;
$num = mysql_num_rows($result);

for($i = 0;$i<$num;$i++)
{
$arr=mysql_fetch_array($result);
echo str_replace($key,"".$key."",$arr[name])."
";
}
}

?>