array_sum() returns zero
Posted: Mon Feb 20, 2012 1:32 pm
Hey all,
I getting an array from mysql and trying to sum the results. The function always return zero. What am I doing wrong?
btw. the array from the mysql looks this:
Array ( [0] => Array ( [q1] => 1 [q3] => 1 [q7] => 0 [q10] => 0 [q13] => 0 [q14] => 0 [q19] => 1 [q22] => 0 [q25] => 0 [q27] => 1 [q30] => 0 [q33] => 1 [q35] => 1 [q36] => 0 ) )
Thanks,
I getting an array from mysql and trying to sum the results. The function always return zero. What am I doing wrong?
Code: Select all
include "conn.php";
$query1 = "SELECT q1, q3, q7, q10, q13, q14, q19, q22, q25, q27, q30, q33, q35, q36 FROM shiva WHERE subjectId = ".$subject."";
$result1 = mysql_query($query1) or die(mysql_error());
while($row1=mysql_fetch_assoc($result1))
{
$E_array[] = $row1;
$Etos = array_sum($E_array);
Array ( [0] => Array ( [q1] => 1 [q3] => 1 [q7] => 0 [q10] => 0 [q13] => 0 [q14] => 0 [q19] => 1 [q22] => 0 [q25] => 0 [q27] => 1 [q30] => 0 [q33] => 1 [q35] => 1 [q36] => 0 ) )
Thanks,