Hi all i've had help from bluefleet (BF) with a mysql query which i've now put in a php file, the query works fine but i find i need to get extra data as well as the count, so what i need is when a match is found i need to look up the username in table tview3.
Whichever table the ip match is found there will be a column called UID, in the table tview3 there will also be a column called USERNAME, what i'd like to do is get the username(s) for the matches and then use them in a text file.
I have to state i'm a complete newbie at this, all help is appreciated
$myquery= "select sum(total)
from
(
SELECT count(*) as total
FROM " .TABLE_PREFIX."tview v
where v.ipaddress = '$ips'
union all
SELECT count(*) as total
FROM " .TABLE_PREFIX."tview2 v1
where v1.ipaddress = '$ips'
union all
SELECT count(*) as total
FROM " .TABLE_PREFIX."tview3 v3
where v3.ipaddress = '$ips'
) src";
$result = mysql_query($myquery);
$rowCount = mysql_num_rows($result);
If($rowCount !=0){
echo "NOT EMPTY";
}else{
echo "EMPTY";
}
mysql_free_result($result);
$UAM = strtoupper($_SERVER['HTTP_USER_AGENT']);
$ips = strtoupper($_SERVER['REMOTE_ADDR']);
$fp = fopen("logtext.txt", "a");
$DateOfRequest = date('m-d-Y H:i:s');
fwrite($fp, "$DateOfRequest . \nMatched Member: . $username . \nWith User Agent: . $UAM . \n\nIP: . $ips . \n\n");
So i'd like to populate a variable $username with the username(s) where the matches were found.
Regards, Silo
Change:
SELECT count(*) as total
to
SELECT count(*) as total, username
Then you could do something like:
$row = mysql_fetch_array($query);
$username = $row['username'];
Hope that helps. Also check out this question for a bit more detail: How do I find the most common result in a column in my MySQL table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.