I produced these 3 lines of code and expected it to have created an array with 4 columns and 16 rows
$conn = mysqli_connect('localhost','root','','sharediary';
$sql = "SELECT `tax_year`, `payment_number`, `company_name`, SUM(dividend_payable) FROM `shareholding` GROUP BY company_name, tax_year, payment_number WITH ROLLUP";
$records = mysqli_query($conn,$sql);
And indeed I can display the resuts in a browser using
while($row = mysqli_fetch_array($records))
echo "<tr>";
echo "<td>".$row['tax_year']."</td>";
echo "<td>".$row['payment_number']."</td>";
echo "<td>".$row['company_name']."</td>";
echo "<td>".$row['SUM(dividend_payable)']."</td>";
echo "</tr>";
Et Cetera
within an html table
But then I needed to do some tweaking of the layout but this relied on $record being an array,
but it appears that MySQL does not think it is an array !?!? Here is the story...
I googled around and found 4 methods to display the contents of an array
the first 3 viz. print_r, a user defined function based on print_r and vardump
told me that there are 4 columns and 16 rows which would be true,
but they did not display the contents of my supposed array.
When I tried a 4th method viz. a for loop thus,
for ($i=0;$i<count($records);$i++) {echo $records($i);}
But this time MySQL coughed up an error message ...
Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\showonscreen2.php on line 76
So I tried this as a kind of debugging tool...
if (!is_array($records)) {echo "No, I'm not an array";}
and it did indeed echo to screen the bad news "No, I'm not an array"