我有一种方法可以计算和更新赞助商但是确实它确实有效,但它的回报率更高,而且计数不准确。
这是我的代码
public function get_sponsor($downline_username,$user_name){
if(!isset($downline_username)){
return;
}
//prevent sponsor to count itself
if ($downline_username == $user_name) {
return;
}
//first update this sponsor before update sponsor sponsor
$counter =$this->count_dis_sponsor($downline_username);
$counter =$counter+1;
$data =array('counter'=>$counter);
$this->db->set($data);
$this->db->where('downline_name',$downline_username);
$this->db->update('downlines_counter');
//look for sponsor sponsor
$this->db->where('downline_username',$downline_username);
$query =$this->db->get('downlines');
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$sponsor_id =$row['sponsor_id_fk'];
echo $sponsor_id.' sponsor';
if($sponsor_id !='' && isset($sponsor_id)) {
//update the counter table
$counter = $this->count_dis_sponsor($sponsor_id);
$counter = $counter + 1;
$data = ['counter' => $counter];
$this->db->set($data);
$this->db->where('downline_name', $sponsor_id);
$this->db->update('downlines_counter');
if ($sponsor_id != '' && isset($sponsor_id)) {
$this->get_sponsor($sponsor_id,$user_name);
}
}
}
}
}
所以它继续两次打电话给赞助商赞助商 感谢
答案 0 :(得分:0)
在赞助商赞助商代码区块,也许您可以添加条件验证,就像当前赞助商一样:
...
//look for sponsor sponsor
$this->db->where('downline_username',$downline_username);
$query =$this->db->get('downlines');
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$sponsor_id =$row['sponsor_id_fk'];
echo $sponsor_id.' sponsor';
if($sponsor_id !='' && isset($sponsor_id)) {
//prevent sponsor sponsor to count itself
if ($sponsor_id == $user_name) {
return;
}
//update the counter table
$counter = $this->count_dis_sponsor($sponsor_id);
$counter = $counter + 1;
$data = ['counter' => $counter];
$this->db->set($data);
$this->db->where('downline_name', $sponsor_id);
$this->db->update('downlines_counter');
// if ($sponsor_id != '' && isset($sponsor_id)) {
$this->get_sponsor($sponsor_id,$user_name);
// }
}
}
}
...
在该代码块的内部,这种情况毫无用处:
if ($sponsor_id != '' && isset($sponsor_id)) {
因为它位于完全相同的条件逻辑的内部,并且$sponsor_id
根本没有改变,所以它总是会被传递。