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