function _update_user_points($table = '', $uid = '', $points_to_subtract = 0) { // Ensure table and UID are provided to avoid errors if (empty($table) || empty($uid)) { return FALSE; // Return false if table or uid is not specified } // Create the SQL query to update points with parameterized query $sql = "UPDATE $table SET points = GREATEST(points - ?, 0) WHERE uid = ?"; // Execute the query with bound parameters $this->db->query($sql, array($points_to_subtract, $uid)); return TRUE; } function _get_uid_check_points($table = '', $data = array()) { // Assuming $data['uid'] contains the user ID if (isset($data['uid'])) { // Create the SQL query to get the total points for the user $sql = " SELECT uid, SUM(points) AS total_points FROM $table WHERE uid = ? GROUP BY uid"; // Execute the query with the user ID as a bound parameter $qry = $this->db->query($sql, array($data['uid'])); $row = $qry->row(); if ($row) { // Determine point status based on total points $point_status = ($row->total_points > 0) ? 'valid' : 'not'; $res = array( 'uid' => $row->uid, 'total_points' => $row->total_points, 'point_status' => $point_status ); return $res; } else { return FALSE; // User not found } } else { return FALSE; // UID not provided in the data array } }