How can I build a referral system in PHP?

后端 未结 1 391
失恋的感觉
失恋的感觉 2020-12-21 21:53

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

相关标签:
1条回答
  • 2020-12-21 22:29

    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 讨论(0)
提交回复
热议问题