Calculate average inserted fields in a database table row

This is Calculate average  inserted  fields in a database table  row.this is simple coding to calculate a  percentage  %.Read this full coding to this very simple to calculate.This css also  very simple to create.


 

Calculate Average :

<?php
$connect_db = mysql_connect('localhost','root','');//connect  database
mysql_select_db('m_matri',$connect_db); //select database 
$result = mysql_query("select * from users where id='15'");
while($row = mysql_fetch_row($result)){
$empty_count = 0;
$count = count($row);
for($i = 0; $i < $count; $i++)
if($row[$i] === '' || $row[$i] === 'NULL' || $row[$i] === '0')
$empty_count++;
$update_percentage=((int)(100*(1-$empty_count/($count-1))));
}
?>

Select table in a database


$result = mysql_query("select * from users where id='15'");

Count the total field in table

$count = count($row);

Count the empty field in table

if($row[$i] === '' || $row[$i] === 'NULL' || $row[$i] === '0')
$empty_count++;

Calculate a average  fields a inserted  in table  :

$update_percentage=((int)(100*(1-$empty_count/($count-1))));

Source code:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calcuate percentage in database table filling field </title>
<style type="text/css">
.bar_percentage {border-radius: 5px 5px 5px 5px;border: 1px solid #46A3FF;width:100px;height: 20px;text-align:center;}
.percentage {border-top-left-radius: 4px;border-bottom-left-radius: 4px;width: 10px;height: 20px;background: linear-gradient(to bottom, #3C9DFF 0px, #0095DD 50%, #06C 100%) repeat scroll 0% 0% transparent;}
</style>
</head>
<body>
<?php
$connect_db = mysql_connect('localhost','root','');
mysql_select_db('m_matri',$connect_db);
$result = mysql_query("select * from users where id='15'");
while($row = mysql_fetch_row($result)){
$empty_count = 0;
$count = count($row);
for($i = 0; $i < $count; $i++)
if($row[$i] === '' || $row[$i] === 'NULL' || $row[$i] === '0')
$empty_count++;
$update_percentage=((int)(100*(1-$empty_count/($count-1))));
}
?>
<div align="center">
<h2>Calcuate percentage in database table filling field </h2>
<div class="bar_percentage">
<span style="position:absolute;"><?php echo $update_percentage."%"; ?></span>
<div class="percentage" style="width:<?php echo $update_percentage."%"; ?>"><!-- --></div>
</div>
</div>
</body>
</html>

No comments:

Post a Comment