I want to build a script that will track users, and the people they bring to my site. I also want to track the indirect users they bring also.
I am looking for anyones input on this. My idea is to create a table, that holds the ID of the user, and another field of the id of the user they brought to the site.
-----TableA----
userID | leadID
1 | 5
1 | 6
5 | 7
7 | 9
1 |10
10 | 11
9 | 14
9 |17
21 |22
$sql = mysql_query("SELECT * FROM TableA WHERE userID = '1'");
//count results
if(mysql_num_rows($sql)>0){
//if we have results, gather data
while($r=mysql_fetch_assoc($sql)) {
//re-query to check for indirect leads?
}
}
This would return leadIDs 5,6 and 10.
As we can see, 5 and 10 also brought a few people to the site.
5 brought 7 and 7 brought 9 who then brought 14 and 17
I want to query and come up with everyone, direct or indirect who was brought to the site.
Any ideas on the queries I would perform, or better ideas on table layout.