subhomoy Posted January 16, 2012 Share Posted January 16, 2012 Suppose i have created a database and i have created a table by using the code below Quote CREATE TABLE `track` ( `id` int(6) NOT NULL auto_increment, `tm` varchar(15) NOT NULL default '', `ref` varchar(250) NOT NULL default '', `agent` varchar(250) NOT NULL default '', `ip` varchar(20) NOT NULL default '', `ip_value` int(11) NOT NULL default '0', `domain` varchar(20) NOT NULL default '', `tracking_page_name` varchar(10) NOT NULL default '', UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; and the script to store the details in that database is below Quote $tm=time(); $ref=@$HTTP_REFERER; $agent=@$HTTP_USER_AGENT; $ip=@$REMOTE_ADDR; $strSQL = "INSERT INTO track(tm, ref, agent, ip, tracking_page_name) VALUES ('$tm','$ref','$agent','$ip','$tracking_page_name')"; $test=mysql_query($strSQL); i want to know that if i have 10 ip in that database out of which there are 3 ip's are same. is there any way in which it will show there are only 7 ip ( as 3 ip's are same) Any help would be appreciated... if possible can you provide the code..... thanks in advance... Link to comment https://forums.phpfreaks.com/topic/255118-mysql-help/ Share on other sites More sharing options...
mapleleaf Posted January 16, 2012 Share Posted January 16, 2012 SELECT DISTINCT ip Link to comment https://forums.phpfreaks.com/topic/255118-mysql-help/#findComment-1308078 Share on other sites More sharing options...
subhomoy Posted January 16, 2012 Author Share Posted January 16, 2012 can you plz provide the code..... Link to comment https://forums.phpfreaks.com/topic/255118-mysql-help/#findComment-1308082 Share on other sites More sharing options...
AyKay47 Posted January 16, 2012 Share Posted January 16, 2012 Quote can you please provide the code..... should be able to figure it out from the hint, but you'll want something like this, with whatever conditions you want to add. select distinct ip from track Link to comment https://forums.phpfreaks.com/topic/255118-mysql-help/#findComment-1308159 Share on other sites More sharing options...
Andy-H Posted January 16, 2012 Share Posted January 16, 2012 So you want it to show only the 7 unique IP's? SELECT ip FROM track GROUP BY ip HAVING COUNT(ip) = 1 Or you want to show all IP addresses, but only once per address? (8 in total) SELECT ip, COUNT(ip) AS occurences FROM track GROUP BY ip Link to comment https://forums.phpfreaks.com/topic/255118-mysql-help/#findComment-1308163 Share on other sites More sharing options...
subhomoy Posted January 16, 2012 Author Share Posted January 16, 2012 Thanks guys...... Link to comment https://forums.phpfreaks.com/topic/255118-mysql-help/#findComment-1308208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.