0

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!

Edited by grakovski

3
Contributors
5
Replies
17
Views
2 Years
Discussion Span
Last Post by mattster
0

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.

0

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.

0

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.

0

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 ;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.