Hi,
This is more a SQL question that a php one, but here goes:

I have a table with 3 fields, Date, IP, ISP.
Basically I have written some php to store the following in the table each time 
someone hits a page on my site. Now I want to display some info about the users 
currently on my site, but I want to try and do it with 1 SQL query.

Basically I want to display a count of how many unique IPs there are on my site from 
each ISP... for example
3 NTL 
1 BT
5 Freeserve

but in each group there will be more than 1 entry for each user due to them causing a 
row in the table on each hit. I can't seem to group it together how I want with 1 
query. The best I can do is count how many rows are from each IP (but this figure is 
too high since it doesn't take into account that the IPs must be unique). Here is my 
current SQL:

$sql = "SELECT ISP, COUNT(*) as total FROM track GROUP BY ISP ORDER BY total DESC";

I could make this work by doing some sorting in PHP once I get the data, but I would 
prefer to do it with SQL... Anyone know how to do what I want?

Thanks
Andrew

Reply via email to