Reputation:
I know how to get the number of rows using mysql_num_rows. What i want to do is count each ip address, so i can count how many diffrent ip addresses are in my db. if that makes sense lol. cause there is just over 1,000 records. so let me show you a quick example.
say i have these ip addresses.
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.2
127.0.0.2
127.0.0.3
127.0.0.3
i want it to count 1 of each. and print 3 or whatever ammount i have in my database not count all which is what mysql_num_rows does and prints 7.
sorry if the title isn't very specific.
Upvotes: 1
Views: 130
Reputation: 17380
Use the MySQL Distinct Clause
SELECT DISTINCT IpAddress FROM MyTable
Upvotes: 0
Reputation: 247
Use DISTINCT
to count once. Not involving the duplicates. Try this query:
SELECT COUNT(DISTINCT IP)
FROM table_name;
Upvotes: 2
Reputation: 19552
Use the distinct
and count
features together:
SELECT COUNT(distinct ip_address) FROM some_table;
Upvotes: 6