I am having trouble with one of my scripts. What basically happens is that my use of mysqli_data_seek() and mysqli_fetch_assoc() produces the following error:
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
This is the code relating to those two lines:
mysqli_data_seek($subsSql, 0);
while($rowSubs = mysqli_fetch_assoc($subsSql))
These errors only occur when the script runs on my hosted (live) website. In my local development (latest version of WAMP) this script runs without error and produces the desired effect…
Here is the script in its full context:
//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)
{
...
}
...
}
Could someone by chance spot a problem with the way I have coded this script or possibly suggest a reason as to why this would work via wamp and not the apache server used with my web host?
Any suggestions or advice relating to this would be greatly appreciated!
Thanks for your time in reading through this!
The Documentation for mysqli_query says
That means that your query failed. Ensure that $link is connected ok, and double check the syntax of the $subsQuery and $catsSql.