我正在建立一个分类网站,但每个类别都有自己的字段,当我生成字段时出现一个错误的添加页面
NULL
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/test.com/inc/db.inc.php on line 36
这是我使用的功能
function getCategoryFieldsById($cid)
{
$sql = "select * from fields where categoryID = $cid order by fi_order";
$result = $this->query($sql);
$no = $this->getNumRows($result);
if($no)
{ return $result; }
else
{
$pid = $this->getParentId($cid);
if($pid)
$this->getCategoryFieldsById($pid);
else
return 0;
}
}
问题是代表数据库行返回 NULL,我可以打印 $no 并看到有 14 行但是当进入 if() 时它看不到数字
select * from fields where categoryID = 35 order by fi_order
0
select * from fields where categoryID = 34 order by fi_order
0
select * from fields where categoryID = 1 order by fi_order
14
NULL
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/izomart.com/inc/db.inc.php on line 36
这是我的 MySQL 函数
function query($query) {
$this->theQuery = $query;
$result=mysql_query($query) or print(mysql_error());
return $result;
}
function getNumRows($result){
return mysql_num_rows($result);
}