Welcome Guest, Not a member yet? Register   Sign In
need help about database query builder
#3

If you are:
  • Using Active Record
  • Updating a specific user and know their user_id
Then you could try something like this:
Code:
$newTotalPoints = 123456;

$qry = $this->db->select('totalPoints')->get_where('points',array('user_id'=>$user_id));

if( $qry->num_rows() ) {

   $currentTotalPoints = $qry->row_array()['totalPoints'];

   if( $newTotalPoints > $currentTotalPoints ) {

       $this->db->where('user_id',$user_id)->update('points',array('totalPoints'=>$newTotalPoints));

   } else if( $newTotalPoints < $currentTotalPoints ) {

       $this->db->where('user_id',$user_id)->update('points',array('totalPoints'=>$newTotalPoints+$currentTotalPoints));

   }

}
Reply


Messages In This Thread
RE: need help about database query builder - by reactionstudio - 05-22-2017, 03:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB