acctman Posted September 9, 2007 Share Posted September 9, 2007 hi i need to mysql query table rate_referrals then WHERE ref_userid = $userid and add up all the results in ref_points for the selected $userid Link to comment https://forums.phpfreaks.com/topic/68633-solved-mysql-query-and-add-results-in-field/ Share on other sites More sharing options...
Barand Posted September 9, 2007 Share Posted September 9, 2007 SELECT SUM(ref_points) as totalpoints FROM rate_referrals WHERE ref_userid = $userid (moving to mysql forum) Link to comment https://forums.phpfreaks.com/topic/68633-solved-mysql-query-and-add-results-in-field/#findComment-344983 Share on other sites More sharing options...
acctman Posted September 9, 2007 Author Share Posted September 9, 2007 SELECT SUM(ref_points) as totalpoints FROM rate_referrals WHERE ref_userid = $userid (moving to mysql forum) so totalpoints is just a place holder for the sum? something like this would work? $en['totalpts'] = mysql_query("SELECT sum(ref_points) totalpoints FROM `rate_referrals` WHERE `ref_userid` = '{$userid}' "); Link to comment https://forums.phpfreaks.com/topic/68633-solved-mysql-query-and-add-results-in-field/#findComment-344991 Share on other sites More sharing options...
Barand Posted September 9, 2007 Share Posted September 9, 2007 something like this would work? $en['totalpts'] = mysql_query("SELECT sum(ref_points) totalpoints FROM `rate_referrals` WHERE `ref_userid` = '{$userid}' "); No. <?php $res = mysql_query("SELECT sum(ref_points) as totalpoints FROM `rate_referrals` WHERE `ref_userid` = '{$userid}' "); $en['totalpts'] = mysql_result($res,0,'totalpoints'); ?> Link to comment https://forums.phpfreaks.com/topic/68633-solved-mysql-query-and-add-results-in-field/#findComment-345020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.