我希望分支机构能够看到他们有多少推荐人。
所以我的表有3列:id
,IP
,username
和referee
。会员可以拥有多个帐户。
这是我到目前为止所拥有的。
//Get all of that IP's usernames
$sql = "SELECT username FROM ".MYSQLTABLE." WHERE ip = '" . $_SERVER['REMOTE_ADDR']."'";
$res = mysql_query($sql)or die(mysql_error());
//Select all usernames, who's referee = one of IP's usernames (using above query)
$sql1 = "SELECT usernames FROM ".MYSQLTABLE." WHERE referee = '".$res."'";
$res1 = mysql_query($sql1)or die(mysql_error());
while($row=mysql_fetch_array($res1))
{
答案 0 :(得分:0)
你可以这样做是一个单一的查询,简化了事情:
SELECT DISTINCT(u.username)
FROM yourTable u
INNER JOIN yourTable r ON (r.username = u.referee AND r.ip = 'TheIP');