Php Codeigniter每3次识别一次用户注册转介
我目前正在开发一个使用Codeigniter框架的传销网站 我现在正在办理注册手续。我可以向推荐用户成功注册 问题是每3次使用我的推荐用户名/id注册,我需要运行另一个查询,因为在第一次和第二次推荐中,我获得了200。在第三个用户将参考我将只赚100Php Codeigniter每3次识别一次用户注册转介,php,codeigniter,Php,Codeigniter,我目前正在开发一个使用Codeigniter框架的传销网站 我现在正在办理注册手续。我可以向推荐用户成功注册 问题是每3次使用我的推荐用户名/id注册,我需要运行另一个查询,因为在第一次和第二次推荐中,我获得了200。在第三个用户将参考我将只赚100 我如何在Codeigniter中做到这一点?有人这样做吗?请帮帮我让我解释一下 因此,假设您为每个注册创建一个post,post将转到一个类名注册和一个register方法,并且引用id作为会话(refID)运行。此外,您有一个注册模型,这是您应该
我如何在Codeigniter中做到这一点?有人这样做吗?请帮帮我让我解释一下 因此,假设您为每个注册创建一个post,post将转到一个类名注册和一个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
}
}
}
我希望这能解释你真正想要什么,并对你有所帮助。如果您发现任何困难,请发表评论,让我们来解决。Codeigniter与您的问题无关。您不能根据转介ID计算注册数,例如,从转介ID为“XXXXXX”的注册中选择计数(*);如果这个数字是2,那么你知道这是第三次注册了吗?谢谢你的回答兄弟:)谢谢@sunday这真的帮助了我:)这正是我需要的。再次谢谢你我可以再请你帮忙吗?我会发布新问题好的,请发布,我会相应地提供帮助
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();
}
}