[英]Codeigniter Identify Every 3rd user Registration referral
我目前正在使用Codeigniter Framework開發一個MLM網站。
我現在正在注冊。 我可以向推薦用戶注冊成功
問題是每3個使用我的推薦用戶名/ ID進行注冊,我都需要運行另一個查詢,因為在第一和第二推薦中我賺了200。在第三用戶中,我只能賺100。
如何在Codeigniter中做到這一點? 有人這樣做嗎? 請幫忙
讓我對此進行一些說明。因此,可以說您為每個注冊創建了一個帖子,該帖子轉到了一個類名注冊和一個register方法,並且引用id作為會話(refID)運行。 另外,您有一個注冊模型,這可能是您應該做的:
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
}
}
}
現在這就是您的注冊模型的樣子
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();
}
}
我希望這可以解釋您的真正需求並為您提供幫助。 如果發現任何困難,請發表評論並進行整理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.