I have a last problem. It is regarding the ROWS vs. VALUES.
Thanks for the help guys and I regretted not taking the
programming as my specialisation.
See this codes:
<?php
$query = "SELECT income FROM customer";
$result = mysql_query($query);
$totalrows = mysql_num_rows($result);
$sum=0;
while($result_array=mysql_fetch_array($result))
$sum+=$result_array['income'];
// This was taken from the post above and the
VALUE IS < $377413 >
$query2 = "SELECT SUM(cust_id) FROM customer
ORDER BY cust_id ASC";
$result2 = mysql_query($query2) or
die(mysql_error());
$row2 =
mysql_num_rows($result2);
// This was done and the RESULT IS
<88>
// Now I want to do is an average Income/customer and the
logical answer is $4288
// So logically this is done like that isn't it?
$row3 = FLOOR($sum/$row2);
echo $row3;
// But how come it the result is $0...? I suspect that this is
the rows issues...
?>
Any help guys?
can try
$query2 = "SELECT SUM(cust_id) FROM customer
ORDER BY cust_id ASC";
$result2 = mysql_query($query2) or
die(mysql_error());
$row2 = (int)
mysql_num_rows($result2);
and
$query = "SELECT income FROM customer";
$result = mysql_query($query);
$totalrows = mysql_num_rows($result);
$sum=0;
while($result_array=mysql_fetch_array($result))
$sum+=(int)
$result_array['income'];
and see what's the result? I am afraid typecasting may be the
problem here.
In any case, maybe you would like to try this instead:
$query = "SELECT FLOOR(AVG(income)) average
FROM customer ORDER BY cust_id ASC";
$result = mysql_query($query) or
die(mysql_error());
$average = (int)
mysql_fetch_array['average'];
echo $average;