lalnfl Posted February 13, 2011 Share Posted February 13, 2011 $sql_get_match = mysql_query("SELECT length FROM Match_1v1 WHERE show_id='$show_id'"); $get_match = array_sum(mysql_fetch_array($sql_get_match)); I have two fields in the database with length's of 31 and 29, but it comes out as a total of 58. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/227561-array_sum-not-working/ Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 29 + 29 = 58. You're getting the sum of the 2 array elements returned by mysql_fetch_array() for the last record returned. mysql_fetch_array() returns both an associative and an enumerated array. Link to comment https://forums.phpfreaks.com/topic/227561-array_sum-not-working/#findComment-1173789 Share on other sites More sharing options...
lalnfl Posted February 13, 2011 Author Share Posted February 13, 2011 What would my solution be then to get 60? Link to comment https://forums.phpfreaks.com/topic/227561-array_sum-not-working/#findComment-1173796 Share on other sites More sharing options...
lalnfl Posted February 13, 2011 Author Share Posted February 13, 2011 $sql_get_match = mysql_query("SELECT SUM(length) FROM Match_1v1 WHERE show_id='$show_id'"); $get_match = mysql_result($sql_get_match, 0); This seems to fix the problem. Link to comment https://forums.phpfreaks.com/topic/227561-array_sum-not-working/#findComment-1173803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.