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 create a contract with Solidity? 
Php :: Comment rediriger la page “Panier” et sauter la page Commande 
Php :: php increase response time 
Php :: how exactly works prompt parameter wp skipping password 
Php :: ring create an RSA key from PEM encoded string 
Php :: write to error log opencart 
Php :: php isset and test 
Php :: function to find total number of students in wplms 
Php :: tutorial crud phpmyadmin 
Php :: what does php stand for 
Php :: building an ecommerce website with laravel 
Php :: php pdo bindvalue array 
Php :: php pesos en letras rutina 
Php :: array inserted in laravel 
Php :: PHP soundex — Calculate the soundex key of a string 
Php :: laravel where search like with space 
Php :: show data as per url slug change in laravel 
Php :: acf select multiple choice array in loop 
Php :: lazy loading vs eager loading laravel 
Php :: Save custom input field value into cart item 
Php :: laravel integer data type 
Php :: Calling the JS file via WP PHP 
Php :: Get page title, excerpt or content by id 
Php :: Laravel display the date the participation was created 
Php :: require and include difference in laravel 
Php :: Add ACF to single.php 
Php :: php type generic object 
Php :: wordpress not recognizing function during plugin activation 
Php :: php print products with attribute 
Php :: configurar pagina html php para mobile 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =