i'm trying to add 25 to the result of a mysql sum query and it's telling me: Unsupported operand types in /home/content/s/a/l/xxxxxxx/html/people/index2.php on line 92 here is the code.. i'm a newbie with PHP but this doesn't make sense.. $resultm = mysql_query("SELECT *,SUM(point.point_value) AS month_total FROM point_tracking LEFT JOIN point ON point_tracking.point_id=point.point_id WHERE point_tracking.member_id='".$_SESSION['id']."' AND entry_date LIKE '".date('Y-m')."%'"); $mpoints=mysql_fetch_array($resultm); $mpoints = $mpoints + 25; $resulty = mysql_query("SELECT *,SUM(point.point_value) AS year_total FROM point_tracking LEFT JOIN point ON point_tracking.point_id=point.point_id WHERE point_tracking.member_id='".$_SESSION['id']."' AND entry_date LIKE '".date('Y')."%'"); $ypoints=mysql_fetch_array($resulty); $ypoints=$ypoints + 25; the line with the error is "$mpoints = $mpoints + 25;"
If you just want to add 25 to the item IN the array, change it to this: $ypoints['month_total'] += 25; PHP: Another option would be to do it right in the SQL query... $resulty = mysql_query("SELECT *,SUM(point.point_value) + 25 AS year_total FROM point_tracking LEFT JOIN point ON point_tracking.point_id=point.point_id WHERE point_tracking.member_id='".$_SESSION['id']."' AND entry_date LIKE '".date('Y')."%'"); PHP: Side note - you really would be better off using mysqli extensions since the ones you are using are deprecated and will be removed from PHP at some point. http://www.php.net/manual/en/class.mysqli.php
the second option $resulty = mysql_query("SELECT *,SUM(point.point_value) + 25 AS year_total FROM point_tracking LEFT JOIN point ON point_tracking.point_id=point.point_id WHERE point_tracking.member_id='".$_SESSION['id']."' AND entry_date LIKE '".date('Y')."%'"); Code (markup): seems to add 25 to each record instead of the total - so for example if there were 10 records, the total ends up being 250 too high..
It shouldn't add 25 for each record unless the + 25 was inside the parentheses like so: SUM(point.point_value + 25) Code (sql): It should be outside, like this: SUM(point.point_value) + 25 Code (sql):