简体   繁体   中英

Codeigniter Identify Every 3rd user Registration referral

I'm currently developing an MLM Website using Codeigniter Framework.

And I am working on registration now. I can register successful with referral user

The problem is every 3 registration using my referral username/id i need to run another query because in 1st and 2nd referral I earned 200. and in 3rd user will refer i will only earn 100.

How can I do that in Codeigniter? anyone done this? please help

Let me throw some light on this So lets say you make a post for every registration, the post goes to a class names registration and a register method, and the referral id runs as a session (refID). Also, you have a registration model, this is what you should likely do:

class registration extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->model('registration_model');
    }

    //ensue to check for the existence of the refID session before processing
    function register(){

        if($_POST){
            //first run form validation
            //you should have auto loaded the form_validation library
            //and created a rules function that carries the form rules
            $rules = $this->rules();
            $this->form_validation->set_rules($rules);

            if($this->form_validation->run() == FALSE){
                //load view here
            }else{
                //first, get post data
                //then get the number of registration done by user using the refID
                //if registration is greater than 2, set earnings to 100
                //set earnings to 200
                //then proceed to insert registration and do something 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 the earnings from the number of registrations
                $earning = $numOfRegs < 3 ? 200 : 100;
                //please note that the for $numOfRegs = 4, $earnings will be 100, as this was not specified in the question

                //at this point, you have set the earnings, you can proceed to do whatever you wish to do, perhaps insert the records

                //please note that this code block just explains what you can likely do after setting the earnings
                $insert = array(
                    "name" => $name,
                    "email" => $email,
                    "earning" => $earning
                );
                $this->registration_model->insert($array);
                // then do anything else
            }
        }else{
            //load view here
        }
    }
}

Now this is how your registration model will look like 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 this explains what you really wants, and helps you. If you find any difficulty, kindly comment and lets sort it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM