This question already has an answer here:
<?php
$con=mysqli_connect("localhost","xxx","xxx","xx");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = mysqli_query($con,"SELECT username, COUNT(username) AS total FROM xxxxx GROUP BY username");
$array = array();
while($fetch = mysqli_fetch_assoc($sql))
{
$array[$fetch['username']] = $fetch['total'];
}
echo '<pre>'; print_r($array);
mysqli_close($con);
?>
Below is the error that i am receiving
Error::: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/xxxxx.php on line 20
Thanks for help
</div>
try this as its not mysql but mysqli
while($fetch = sql->fetch_assoc())
{
......