你可以存储上线水平,你的用户表了。在注册期间,您可以获取上线,然后上线等,以便稍后在查询用户表时获取它们。
我这样做6级深,所以它是6个更多的查询,但我真的不在乎,注册不会发生一天一百万次。
这里是从我的流量交换我的用户表...希望它帮助。正如你所看到的,我还使用upline_val列来存储冲浪积分,稍后可以通过他们的上线声明一个按钮“从推介中索取积分”。
和注册模型代码来创建成员:
$data = array(
'username' => $username,
'password' => password_hash($password, PASSWORD_DEFAULT),
'email' => $email,
'first_name' => $first_name,
'last_name' => $last_name,
'active' => $active,
'referred_by_id' => $referred_by_id,
'referral_url' => $this->session->userdata('referral_url'),
'next_subscription_update' => $now->format("Y-m-d H:i:s"),
'email_newsletter' => $newsletter,
'autoassign_pct' => Settings_model::$db_config['autoassign_value']
);
// select upline ids
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['referred_by_id']); // $data['referred_by_id'] is passed in the url e.g. http://example.com/register/1867
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl2'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl2']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl3'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl3']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl4'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl4']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl5'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl5']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl6'] = $q->row()->referred_by_id;
}
}
}
}
}
// ...etc...
$this->db->insert(DB_PREFIX .'user', $data); // $data is inserted here
这是对所有我能做的,我猜。
向我们显示您的代码。堆栈溢出不是代码写入服务。 –