1

I am working on my UniLevel Multi Level Marketing Web App using Codeigniter Framerwork.

I can successfully add/register new member with referral id/username.

But my problem is I want the new member referred by me Become My Level 1..

Me

New member referred by me (becomes my level 1) And if that member(my level 1) Refer another member.. the new referred member Will become my Level 2.

So its. from level 0(me) to level 1(member referred by me) to level 2(the member referred by level 1.

I hope you guys understands my Explanation..

1 Answers1

1

I use a referred_by_id table column to store the parent of the new member. This referred_by_id holds the user_id of the parent.

CREATE TABLE `user` (
  `user_id` int(11) UNSIGNED NOT NULL,
  `referred_by_id` int(11) UNSIGNED NOT NULL DEFAULT '0'
etc...

When Kurt registers under administrator, he becomes a level 1 referral for admin. When Frank registers under Kurt, he becomes a level 1 for Kurt and level 2 for administrator. Repeat ad nauseam. You decide what you want to show to the users: how many levels deep.

To count referrals (is just an example to get you going):

$this->db->select('u.user_id,
        (select count(user_id) from '. DB_PREFIX .'user where referred_by_id = u.user_id) as total_referred');
$this->db->from(DB_PREFIX .'user u');
$this->db->where('u.referred_by_id', $this->session->userdata('user_id'));

addendum: during registration you can keep track of a session variable with the parent user_id taken from the url segments. You can also store it in a cookie (first come first serve principle) to use the id of the person whose page you saw first.

qwertzman
  • 784
  • 1
  • 9
  • 23
  • Thanks for your comme @qwertzman But how can i insert that? user to level 1 and to level to and so on? – Konjesh Esbrading Aug 23 '17 at 08:00
  • If you add the direct parent (referred_by_id) you will automatically grow a tree of members. So in your registration insert query you add the field. – qwertzman Aug 24 '17 at 16:24
  • I can successfully save now.. How can I give them the Rewards? – Konjesh Esbrading Aug 26 '17 at 06:22
  • Rewards? You mean for signing up? Might be a different question. – qwertzman Aug 26 '17 at 09:37
  • I found your other question. https://stackoverflow.com/questions/45892586/distribute-rewards-to-different-level-in-codeigniter-unilevel-mlm So what I do is add a column for each level and work with a claim button. Maybe it's easier I send you my user table as example because it's complex. – qwertzman Aug 26 '17 at 10:01
  • Apparently I can't contact you via SO -.- – qwertzman Aug 28 '17 at 16:26