I am querying a database. Then inserting the resultant values into an array and finding their sum. This is the code:
$result=mysql_query("SELECT items FROM mytable WHERE user_id='$id'");
$array=array();
while($row=mysql_fetch_assoc($result)){
//insert values into array
$array=$row;
$sum=array_sum($row);
echo $sum;
}
This just returns the items in the array and not the sum. How do I correct that? Ps:I had tried this here earlier, but it halves the correct result:
$result=mysql_query("SELECT items FROM mytable WHERE user_id='$id'");
$row = mysql_fetch_array($result, MYSQL_NUM);
$sum = array_sum($row);
echo $sum;
Thanks