我有一个查询(如下),它将检查 3 个表中的匹配项。所有 3 个表都有 UID 和 IPADDRESS 列;第三个表也有 USERNAME。如何更改下面的查询以使用与 ipaddress 匹配的唯一用户名列表填充变量 $username?
因此,在每个表中,ipaddress 匹配的 UID 可能是 2、3、6、6、23、2、6,因为有多个条目,并且有人可能欺骗了其他 ip。我想要的是用与 UID 2、3、6、23(唯一列表)匹配的用户名填充 $username 的查询。我必须告诉你我对 MySQL 和查询完全陌生。这是查询:
error_reporting(E_ALL & ~E_NOTICE & ~8192);
$UAM = strtoupper($_SERVER['HTTP_USER_AGENT']);
$ips = strtoupper($_SERVER['REMOTE_ADDR']);
$myquery= "select sum(total)
FROM (SELECT count(*) as total,userid
FROM " .TABLE_PREFIX."memberviews v
where v.ipaddress = '$ips'
union all
SELECT count(*) as total,userid
FROM " .TABLE_PREFIX."membervisits v1
where v1.ipaddress = '$ips'
union all
SELECT count(*) as total,userid
FROM " .TABLE_PREFIX."user v3
where v3.ipaddress = '$ips'
)src";
$result = mysql_query($myquery);
$rowCount = mysql_num_rows($myquery);
$row = mysql_fetch_array($myquery);
$username = $row['userid'];
If($rowCount !=0){
$fp = fopen("logtext.txt", "a");
$DateOfRequest = date('m-d-Y H:i:s');
fwrite($fp, "Registration Attempt\n\nDate: . $DateOfRequest . \nMatched Member: . $username . \nWith User Agent: . $UAM . \nIP: . $ips . \n\n");
}
mysql_free_result($myquery);
当前,查询的工作量与写入文件的时间一样多。所有帮助表示赞赏:)