php - Codeigniter Identify Every 3rd user Registration referral -
i'm developing mlm website using codeigniter framework.
and working on registration now. can register successful referral user
the problem every 3 registration using referral username/id need run query because in 1st , 2nd referral earned 200. , in 3rd user refer earn 100.
how can in codeigniter? done this? please help
let me throw light on lets make post every registration, post goes class names registration , register method, , referral id runs session (refid). also, have registration model, should do:
class registration extends ci_controller{ function __construct(){ parent::__construct(); $this->load->model('registration_model'); } //ensue check existence of refid session before processing function register(){ if($_post){ //first run form validation //you should have auto loaded form_validation library //and created rules function carries form rules $rules = $this->rules(); $this->form_validation->set_rules($rules); if($this->form_validation->run() == false){ //load view here }else{ //first, post data //then number of registration done user using refid //if registration greater 2, set earnings 100 //set earnings 200 //then proceed insert registration , else //get post data, assumed post data $name = $this->input->post('name'); $email = $this->input->post('email'); //get number of registrations $numofregs = $this->registration_model->getregbyrefid(); //set earnings number of registrations $earning = $numofregs < 3 ? 200 : 100; //please note $numofregs = 4, $earnings 100, not specified in question //at point, have set earnings, can proceed whatever wish do, perhaps insert records //please note code block explains can after setting earnings $insert = array( "name" => $name, "email" => $email, "earning" => $earning ); $this->registration_model->insert($array); // else } }else{ //load view here } } }
now how registration model this
class registration_model extends ci_model{ function __construct(){ parent::__construct(); } function getregbyrefid(){ $refid = $this->session->refid; return $this->db->get_where('mydb', array("refid" => $refid))->num_rows(); } }
i hope explains wants, , helps you. if find difficulty, kindly comment , lets sort out.
Comments
Post a Comment