我的一个脚本有问题。基本上发生的是我使用mysqli_data_seek()
并mysqli_fetch_assoc()
产生以下错误:
Warning: mysqli_data_seek() expects parameter 1 to be mysqli_result, boolean given in /usr/home/myacc/includes/html/shop/categoryMain.html.php on line 49
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /usr/home/myacc/includes/html/shop/categoryMain.html.php on line 50
这是与这两行相关的代码:
mysqli_data_seek($subsSql, 0);
while($rowSubs = mysqli_fetch_assoc($subsSql))
这些错误仅在脚本在我的托管(实时)网站上运行时发生。在我的本地开发(最新版本的 WAMP)中,这个脚本运行没有错误并产生预期的效果......
这是完整上下文中的脚本:
//categories to local array
$catsQuery = "
SELECT id, category, catDirPath
FROM categories
ORDER BY category
";
$catsSql = mysqli_query($link, $catsQuery);
$cats = array();
mysqli_data_seek($catsSql, 0);
while($rowCats = mysqli_fetch_assoc($catsSql))
{
$cats[$rowCats['id']]['catName'] = $rowCats['category'];
$cats[$rowCats['id']]['catPath'] = $rowCats['catDirPath'];
}
// subCats to local array
$subsQuery = "
SELECT id, subCat, category_id, subDirPath
FROM subCats, sub_categories
WHERE subCats.id = sub_categories.sub_id
ORDER BY subCat
";
$subsSql = mysqli_query($link, $subsQuery);
$subs = array();
mysqli_data_seek($subsSql, 0);
while($rowSubs = mysqli_fetch_assoc($subsSql))
{
$subs[$rowSubs['id']]['subName'] = $rowSubs['subCat'];
$subs[$rowSubs['id']]['catId'] = $rowSubs['category_id'];
$subs[$rowSubs['id']]['subPath'] = $rowSubs['subDirPath'];
}
// loop through categories and if subs exist, add to resultset and display
foreach ($cats as $catId => $cat)
{
...
foreach ($subs as $subId => $sub)
{
...
}
...
}
有人会偶然发现我编写此脚本的方式存在问题,或者可能提出一个原因,说明为什么这将通过 wamp 而不是与我的网络主机一起使用的 apache 服务器工作?
任何与此相关的建议或意见将不胜感激!
感谢您花时间阅读本文!