Hi,
New here and to PHP, but have previously used ASP.
I’m trying to fetch the results of a DB query into an array and then loop through it. Here’s my code:
[php]<?php
$rsCategories = mysqli_query($connBike,“SELECT CategoryID, CategoryName FROM tbl_Categories”);
// Fetch all
$arrCategories = mysqli_fetch_all($rsCategories,MYSQLI_ASSOC);
// Free result set
mysqli_free_result($rsCategories);
mysqli_close($connBike);
list($intID, $strCategory) = each($arrCategories);
while (list($intID,$strCategory) = each($arrCategories)) {
echo("$intID - $strCategory
\n");
}
?> [/php]
However, I’m obviously missing something as this the result:
Notice: Array to string conversion in C:\xampp\htdocs\PHPsites\Bikes\zzSiteFiles\AdInsert.php on line 15
1 - Array
Notice: Array to string conversion in C:\xampp\htdocs\PHPsites\Bikes\zzSiteFiles\AdInsert.php on line 15
2 - Array
Notice: Array to string conversion in C:\xampp\htdocs\PHPsites\Bikes\zzSiteFiles\AdInsert.php on line 15
3 - Array
etc.
Whereas I want the second variable $strCategory to display the DB value, which would look something like this:
1 - Frames
2 - Forks
3 - Drivetrain
etc.
Any ideas?