mrpaul Posted December 18, 2006 Share Posted December 18, 2006 HelloI'm new to this forum, so firstly, let me say hello to everyone. I am wondering if anyone here can help me? I am creating a simple stats page for one of my websites, I have a sql table which I capture the following;PAGE URLUSER IPThe entire table structure is;idurlipdatetimeSome sample data is1 www.site.co.uk/index.php 76.376.112.236 2006-12-11 34-38-00 2 www.site.co.uk/help.php 23.222.765.345 2006-12-11 41-38-00 3 www.site.co.uk/index.php 76.376.112.236 2006-12-11 54-39-00 Using just the above data, if I do a count on this table I get "3" returned, as there are 3 rows.I want to put a part on my stats page which gives me the total number of unique visitors, I can do this by counting the total rows in the database and then counting any row which has the same `url` and `ip`, as one row, so on the above sample data, it would return "2", as row "1" and "2" have the same value in the fields URL and IP.Can anyone help me out with solving this?RegardsPaul Link to comment https://forums.phpfreaks.com/topic/31081-unique-records-for-my-stats/ Share on other sites More sharing options...
JasonLewis Posted December 18, 2006 Share Posted December 18, 2006 i would suggest using the following:[code=php:0]mysql_query("SELECT DISTINCT(*) FROM table");[/code]think thats what your after... Link to comment https://forums.phpfreaks.com/topic/31081-unique-records-for-my-stats/#findComment-143498 Share on other sites More sharing options...
mrpaul Posted December 18, 2006 Author Share Posted December 18, 2006 Thank you, when I query that, I get the error#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* ) FROM `stats`LIMIT 0, 30' at line 1 Could you help any further Link to comment https://forums.phpfreaks.com/topic/31081-unique-records-for-my-stats/#findComment-143509 Share on other sites More sharing options...
mrpaul Posted December 18, 2006 Author Share Posted December 18, 2006 One thing with that code above, I think that will show all unique rows, but it can count rows with the same URL as more than one result, it should only take multiple rows as one row when the url and i[ match.Does that make much sense? Link to comment https://forums.phpfreaks.com/topic/31081-unique-records-for-my-stats/#findComment-143513 Share on other sites More sharing options...
mrpaul Posted December 18, 2006 Author Share Posted December 18, 2006 Is the code[code]SELECT DISTINCT u.ip, u.url FROM stats u[/code]Correct? Link to comment https://forums.phpfreaks.com/topic/31081-unique-records-for-my-stats/#findComment-143514 Share on other sites More sharing options...
mrpaul Posted December 18, 2006 Author Share Posted December 18, 2006 The above seems to work for me, but is there a way to count the total returned? Link to comment https://forums.phpfreaks.com/topic/31081-unique-records-for-my-stats/#findComment-143516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.