【发布时间】:2013-08-08 05:12:22
【问题描述】:
当我执行下面的函数时,查询执行成功,但我在查询结果上方收到警告:
mysql_num_rows() 期望参数 1 是资源,布尔值
我该如何解决这个问题?
public function retrieve()
{
$id=JRequest::getVar('id');
$db =JFactory::getDBO();
$sql="select *
from
#__npco_car,#__npco_namayeshgah,#__npco_agahi
where
#__npco_car.car_id='$id' and
#__npco_namayeshgah.id_namayeshgah=#__npco_agahi.id_namayeshgah and
#__npco_car.car_id=#__npco_agahi.car_id
";
$db->setQuery($sql);
$db->query();
$row = $db->getNumRows();
if($row == 1) {
return $db->loadAssocList();
} else {
$db = JFactory::getDBO();
$sql="select *
from
#__npco_car,#__npco_useragahi,#__npco_user
where
#__npco_car.car_id='$id' and
#__npco_user.id_user=#__npco_useragahi.id_user and
#__npco_car.car_id=#__npco_useragahi.car_id
";
$db->setQuery($sql);
return $db->loadAssocList();
}
}
【问题讨论】:
-
尝试在
$db =JFactory::getDBO();之后添加$query = $db->getQuery(true);。另外,我假设您使用的是 Joomla 2.5 或 3.x,因此在编写 SQL 查询时,我建议您坚持正确的编码标准;) -
查看此页面的右侧。看看有多少以前的问题被问到完全相同的问题。这意味着您运行了无效查询,但在尝试使用结果之前未检查错误。修复您的查询并添加一些错误处理。