What code would I use to add together all amounts from 'money' in the users table and divide them by all users? Thanks in advance EDIT: Is this right?... <?php session_start(); include_once"includes/db_connect.php"; $select = mysql_query("SELECT * FROM users WHERE userlevel != '6' ORDER by id"); $num = mysql_fetch_object($select); $numm = mysql_num_rows($select); $amount=ROUND($num->money/$numm, 0); echo"$num->money divided by $numm = $amount"; ?> PHP:
Why not let mysql do all the work? This select statement will return one row with one column containing the value you want: select ROUND(SUM(money)/COUNT(*)) FROM users WHERE userlevel != '6' PHP: (substitute the correct money field name for "money")