Good Afternoon, Can someone please point us in the right direction and or kindly explain. I am trying to ECHO / PRINT SQL Query results on a webpage ad will later use to create Charts/Graphs.
For some reason i cannot get my head around alias; Example:
SELECT asset_detail, COUNT(asset_detail) AS TOTAL
FROM `WHS`
WHERE appeared >= now() - interval 21 day
GROUP BY asset_detail
ORDER BY 2 DESC
LIMIT 10;
I am unable to print the TOTAL bit from above Query;
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT asset_detail, COUNT(asset_detail) AS TOTAL
FROM `WHS`
WHERE appeared >= now() - interval 21 day
GROUP BY asset_detail
ORDER BY 2 DESC
LIMIT 10";
$result = mysqli_query($conn, $sql);
// Associative array
$row = mysqli_fetch_assoc($result);
echo "Rows found :" . $result['TOTAL'];
// Free result set
mysqli_free_result($result);
mysqli_close($con);
?>
I am after a total to top 10 assets for rolling 21 days, asset name and count with a view to showcase this information in a graphical form at a later date. I have tried multiple ways of writing the Echo, Print but unable to get results.