brown2005 Posted March 4, 2007 Share Posted March 4, 2007 hits_user hits_user_type hits_date hits_count I have that table and $sql = "SELECT year(hits_date) AS hits_year, COUNT(*) AS hits_unique, SUM(hits_count) AS hits_count FROM z_hits GROUP BY year(hits_date) ORDER BY year(hits_date) DESC;"; which works fine and lists the years with the hits and unique hits, but obviously its not the fully unique hits because it is just counting the rows, so you could have two of the same user in the table, so how would i get around this? thanks in advance Link to comment https://forums.phpfreaks.com/topic/41173-hits/ Share on other sites More sharing options...
marcus Posted March 4, 2007 Share Posted March 4, 2007 Before updating the row check if the row already exists. $sql = "SELECT * FROM `yourtable` WHERE `hits_users` ='whatever'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ //insert new row }else { //update existing row } Link to comment https://forums.phpfreaks.com/topic/41173-hits/#findComment-199453 Share on other sites More sharing options...
brown2005 Posted March 4, 2007 Author Share Posted March 4, 2007 im not updating a row, i am showing hits to my website Link to comment https://forums.phpfreaks.com/topic/41173-hits/#findComment-199460 Share on other sites More sharing options...
pocobueno1388 Posted March 4, 2007 Share Posted March 4, 2007 If you want to show the hits by a specific user, just add to your query: <?php $sql = "SELECT year(hits_date) AS hits_year, COUNT(*) AS hits_unique, SUM(hits_count) AS hits_count FROM z_hits WHERE hits_user = 'username' GROUP BY year(hits_date) ORDER BY year(hits_date) DESC;"; ?> If that is not what you are looking for, I don't understand your question. Link to comment https://forums.phpfreaks.com/topic/41173-hits/#findComment-199466 Share on other sites More sharing options...
brown2005 Posted March 4, 2007 Author Share Posted March 4, 2007 sorry let me explain a bit more, i want to show year hits unique i use year - year(hits_date) AS hits_year hits - SUM(hits_count) AS hits_count unique - COUNT(*) AS hits_unique but obviously the COUNT(*) is countin all the rows, and giving 88 unique users when there is less because some people have visited the site, more than once on different days... Link to comment https://forums.phpfreaks.com/topic/41173-hits/#findComment-199474 Share on other sites More sharing options...
brown2005 Posted March 5, 2007 Author Share Posted March 5, 2007 ne1? Link to comment https://forums.phpfreaks.com/topic/41173-hits/#findComment-199712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.