I have a table called link_track with the following fields: id, uid, ip, hitdate
id is an auto incrementing field
uid is the id of a member from the member table
ip is the ip address of site visitor which generated the new entry to the table
hitdate is the epoch date of the entry of the row to the table
Currently there are the following records in the table:
id uid ip hitdate
28 1 71.61.59.113 1329016727
27 1 71.61.59.113 1329015378
26 1 71.60.19.216 1329007376
What I want to do is find all how many unique IP addresses exist for any one given uid
Currently I am using the following code:
$query = "SELECT COUNT(DISTINCT `ip`) as `count` FROM `link_track` WHERE uid = '".$memID."'";
$results = mysql_query($query);
$statBuffer = mysql_fetch_array($result);
$unique_clicks = mysql_num_rows($result);
echo $unique_clicks;
However this always return a value of 1
You’re getting a
COUNT()aggregate from the database, and callingmysql_num_rows(). The aggregate will always return only one row containing the number of IPs for that user (that’s the1you’re getting), so what you need instead is to get the value from$statBuffer