你可以存儲上線水平,你的用戶表了。在註冊期間,您可以獲取上線,然後上線等,以便稍後在查詢用戶表時獲取它們。
我這樣做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
這是對所有我能做的,我猜。
向我們顯示您的代碼。堆棧溢出不是代碼寫入服務。 –