如何在PHP中构建引用系统?

时间:2021-07-04 10:39:58

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.

我有一个带有referal系统的网站,我希望用户能够使用树视图查看他们引用的用户。

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).

我的数据库表被设置为当用户用他的推荐代码引用某人时,新用户获得一个ID,一个赞助商代码(来自他的“赞助者”的推荐代码,也就是那个让他进入这个网站的人)和一个推荐人代码(他自己的推荐代码让其他人加入他之下)。

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

我不知道如何从我的MySQL数据库中获取此信息,并进入树视图脚本。

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

我需要能够让用户看到他提到的所有人,10级深。

Is this possible and how could I do that?

这可能吗?我怎么能这样做?

1 个解决方案

#1


0  

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

您应该查看分层数据(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);

#1


0  

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

您应该查看分层数据(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);