你早就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;
}
输出 $this->searcher 看看 应该是你的sql 语法错误 建议写成这样
"select * from book where name like '%“.$key.”%'";
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])."
";
}
}
?>