Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to get the average in sql in php

$result = mysql_query("SELECT AVG(fieldName) AS avg FROM tableName");
$row = mysql_fetch_assoc($result); echo $row['avg']
Comment

get average of sql column php

//1 selecting the average from table column
$sql = "SELECT avg(columnName) as whatever FROM tableName";
//2 getting the result
$result = mysqli_query($conn, $sql);
//3 fetch as array
$numratingsa = mysqli_fetch_all($result, MYSQLI_ASSOC);
//4 select last element of array which is average
$myLastElementa = end($numratingsa);
//5 converts array to string
$stringo = implode($myLastElementa);
// *optional* round value to one decimal place
$roundin = round($stringo, 1);
//6 show output
echo $stringo;
echo $roundin;
Comment

PREVIOUS NEXT
Code Example
Php :: how to validate use unique in laravel 8 controller 
Php :: php base64img to file 
Php :: string into integer php 
Php :: sortbydesc on a collection laravel 
Php :: laravel update and insert transaction 
Php :: laravel transform object to array 
Php :: method put laravel 
Php :: what is directory_separator in php 
Php :: getclientoriginalextension laravel 
Php :: custom post type 
Php :: how get the latest arraye value in laravel 
Php :: laravel eloquent get column 
Php :: disable quantity field in woocommerce 
Php :: slug in php 
Php :: random string in laravel 
Php :: http error code php 
Php :: fetch body show in php code 
Php :: php select from database into array 
Php :: php mysqli connect err0r 
Php :: valet laravel 
Php :: upload_max_filesize 
Php :: add to collection laravel 
Php :: php turney if 
Php :: php artisan storage link cpanel 
Php :: how to add recaptcha validation in php 
Php :: joomla cache programing clear 
Php :: laravel echo query 
Php :: wordpress set image quality 
Php :: laravel check my laravel version 
Php :: laravel sortby varchar date 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =