D
D
Darkhan Kamaliev2018-07-09 18:35:08
PHP
Darkhan Kamaliev, 2018-07-09 18:35:08

Transfusion of users into MLM matrix system?

Good day, I have the following code snippet.

$ref_1 = $_SESSION['ref'];
    if ($_SESSION['ref']) {
        /*$ref_1 = $_SESSION['ref'];
        $ref_lvl = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM users WHERE id= $ref_1 "));
        $ref_2 = $ref_lvl[ref_1];
        $ref_3 = $ref_lvl[ref_2];
        $ref_4 = $ref_lvl[ref_3];
        $ref_5 = $ref_lvl[ref_4];
        $ref_6 = $ref_lvl[ref_5]; */
        
    $ref_slot_1 =  mysqli_fetch_assoc(mysqli_query($db, "SELECT ref_slot FROM users WHERE id= $ref_1 "));
    $ref_slot_2 =  mysqli_fetch_assoc(mysqli_query($db, "SELECT ref_slot FROM users WHERE ref_1 = $ref_1 "));
    $ref_slot_3 =  mysqli_fetch_assoc(mysqli_query($db, "SELECT ref_slot FROM users WHERE ref_2 = $ref_1 "));
    $ref_slot_4 =  mysqli_fetch_assoc(mysqli_query($db, "SELECT ref_slot FROM users WHERE ref_3 = $ref_1 "));
    $ref_slot_5 =  mysqli_fetch_assoc(mysqli_query($db, "SELECT ref_slot FROM users WHERE ref_4 = $ref_1 "));
    $ref_slot_6 =  mysqli_fetch_assoc(mysqli_query($db, "SELECT ref_slot FROM users WHERE ref_5 = $ref_1 "));
    
    
        if (ref_slot_1[ref_slot] < 3) {
            $ref_1 = $_SESSION['ref'];
            $ref_lvl = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM users WHERE id= $ref_1 "));
            $ref_2 = $ref_lvl[ref_1];
            $ref_3 = $ref_lvl[ref_2];
            $ref_4 = $ref_lvl[ref_3];
            $ref_5 = $ref_lvl[ref_4];
            $ref_6 = $ref_lvl[ref_5];
        }
    
    
        if ($ref_slot_1[ref_slot] >= 3) {
            if (ref_slot_2[ref_slot] < 3) {
                $ref_lvl = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM users WHERE id= $_SESSION['ref'] "));
                $ref_1 = $ref_lvl[ref_1];
                $ref_2 = $_SESSION['ref'];
                $ref_3 = $ref_lvl[ref_3];
                $ref_4 = $ref_lvl[ref_4];
                $ref_5 = $ref_lvl[ref_5];
                $ref_6 = $ref_lvl[ref_6];
            }
            if (ref_slot_2[ref_slot] >= 3) {
                 if (ref_slot_3[ref_slot] < 3) {
                     $ref_lvl = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM users WHERE id= $_SESSION['ref'] "));
                    $ref_1 = $ref_lvl[ref_1];
                    $ref_2 = $ref_lvl[ref_2];
                    $ref_3 = $ref_lvl[ref_3];
                    $ref_4 = $ref_lvl[ref_4];
                    $ref_5 = $ref_lvl[ref_5];
                    $ref_6 = $ref_lvl[ref_6];
            }
    }
    }
        
  else {
    $ref_1 = 1;
        $ref_2 = 1;
        $ref_3 = 1;
        $ref_4 = 1;
        $ref_5 = 1;
        $ref_6 = 1;
    }

I can not implement the transfusion of users.
Each user can have a maximum of 3 referrals, if more, then you need to refer him to a level below, and so on up to 6 tracked levels. Mind is not enough to think.
I track in the referral database through ref_1 = id ref_2 = id etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-07-19
@darakanoit

Look towards PHP processing with recursion . For MLM matrices, recursion is the very thing. You look, and the code will stop smelling so strongly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question