我面临以下代码的以下错误:
错误:
Warning: Invalid argument supplied for foreach()
代码:
//--------This is the code for jquery UI autocompleter-------------
include "inc/connect.php";
$skeyword = $_GET["term"];
$req = "SELECT p.prm_title ,a.am_name, c.cm_name ,l.lm_name ,b.bm_name,r.pm_name "
. "FROM product_master p,author_master a,category_master c,language_master l,binding_master b ,publisher_master r "
. "WHERE p.prm_title LIKE '%$skeyword%' OR a.am_name LIKE '%$skeyword%'
OR c.cm_name LIKE '%$skeyword%' OR l.lm_name LIKE '%$skeyword%' OR b.bm_name LIKE '%$skeyword%' OR r.pm_name LIKE '%$skeyword%'
GROUP BY p.prm_id LIMIT 10";
$res = mysql_query($req);
$ret = array();
foreach (mysql_fetch_array($res) as $row) {
foreach ($row as $val) //--Error: from this line, Why?
{
if (false !== stripos($val, $skeyword)) {
$ret[] = $val;
break;
}
}
}
$testme = json_encode($ret);
echo $testme;
上面的代码是为 jquery 自动完成器在多列字段中搜索而编写的,但它只会返回匹配的列。
请帮我解决这个问题..