Hi. Sorry for my english (is not good)

I have sql query for get all results by some parameters:
$sql_string = 'SELECT SQL_CALC_FOUND_ROWS ip_ip, ip_time, ip_location, ip_referer, ip_username, ip_user_type, ip_browser FROM ' . IP_TRACK_TABLE;

Is for phpbb3, but it does not matter now.

In this table have 7000 rows with different information. (this is problem)
It logged username, ips and etc.. for user sessions.
I need to get only user information with different ips (ONLY THIS)
Now i have 200-300 rows with ips which are the same. (i dont want this)
I need to get only user information with different ip where column ip_ip have some different ips (not only the same)
Now some example:
if username: Ivan have 200 rows with ip 127.0.0.1 - i dont need to get this row in select query.
But if Todor have 200 rows logged in db with ip 127.0.0.1 and 127.0.0.2 (in ip_ip column) - i need to catch this and print in page.

Please, if someone know how to do that - help me.
Thanks!

Recommended Answers

All 5 Replies

Try by adding GROUP BY ip_username, ip_ip to the current query, it will return all users' ip, or if searching a specific user WHERE ip_username = 'Todor' GROUP BY ip_ip.

Thanks for your reply!
I tried but did not work. I repeat what i want:
When ip_ip column have 2 or more different ips for ip_username - i want to get it. All other results i need to be skipped.

I'm struggling to understand what you want.

Maybe show us how your database is structred etc. so we can maybe begin to understand this a bit better.

OK, here is:

CREATE TABLE IF NOT EXISTS `phpbb_ip_tracking` (
  `ip_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `ip_ip` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '0',
  `ip_time` int(11) unsigned NOT NULL DEFAULT '0',
  `ip_location` text COLLATE utf8_bin NOT NULL,
  `ip_referer` text COLLATE utf8_bin NOT NULL,
  `ip_username` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '0',
  `ip_user_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `ip_user_type` smallint(4) unsigned NOT NULL DEFAULT '0',
  `ip_browser` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '0',
  PRIMARY KEY (`ip_id`),
  KEY `ip` (`ip_ip`),
  KEY `username` (`ip_username`),
  KEY `user_type` (`ip_user_type`),
  KEY `zeit` (`ip_time`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=768029 ;

You might need to see if you can find the duplicate ip_ip first, and then in a separate statement see if they both have the same username.

Look here: http://www.petefreitag.com/item/169.cfm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.