开发者

How can I build a referral system in PHP?

开发者 https://www.devze.com 2023-03-29 16:10 出处:网络
I have a website with a referal system, and I want the users to be able to see what users they referred, using a treeview.

I have a website with a referal system, and I want the users to be able to see what users they referred, using a treeview.

My database table is set up so that when a user refers somebody with his referal code, the new users gets an ID, a sponsor code (the referal code from his "sponser" aka the person who got him into this site) and 开发者_开发技巧a referal code (his own referal code to get other people to join under him).

I have no idea how i can get this info out of my MySQL database, and into a treeview script.

I would need to be able to let the user see all the people that he referred, 10 levels deep.

Is this possible and how could I do that?


You should give a look at hierarchical data (http://www.sitepoint.com/hierarchical-data-database/)

<?php

    function tree_view($index)
    {
        $q = mysql_query("SELECT * FROM table_name WHERE SCode=$index");
        if (!mysql_num_rows($q))
            return;
        echo '<ul>';
        while ($arr = mysql_fetch_assoc($q))
        {
            echo '<li>';
            echo $arr['UserID']; //you can add another output there 
            tree_view($arr['RCode']);
            echo '</li>';
        }
        echo '</ul>';
    }

    mysql_connect('localhost', 'root', '');
    $link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
    mysql_select_db('test') or die('Could not select database');

    tree_view(11111);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号