corrupshun Posted February 7, 2010 Share Posted February 7, 2010 I want to do it like a forum does, where everytime the page loads i could add 1 to the views in the database, while also making sure that the same IP doesn't add more than once? I know i could select the database then count it, then add it, but is there a simplier way (while implementing the same IP concept?) A link would be suffice -Aus THE BOSS Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 7, 2010 Share Posted February 7, 2010 if your pages are generated from content in the db then you will have a db record for each page. This content info in the db needs to have a views field then whenever that page is loaded you include a query to update the views by iincrementing by 1 Quote Link to comment Share on other sites More sharing options...
corrupshun Posted February 7, 2010 Author Share Posted February 7, 2010 if your pages are generated from content in the db then you will have a db record for each page. This content info in the db needs to have a views field then whenever that page is loaded you include a query to update the views by iincrementing by 1 I know that, I'm mostly asking how to check if the same IP has been to the page before, and if so, to not increment it. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 7, 2010 Share Posted February 7, 2010 Ok yes, missed the IP bit. In that case, you would need a separate table that had fields for the page id and the IP. Then the increment function would need to check there to decide to increment or not. Also, the increment function could do the add to that table if not arleady there Quote Link to comment Share on other sites More sharing options...
Buddski Posted February 7, 2010 Share Posted February 7, 2010 You would need to grab the clients IP address and store it in a table.. Then when a person visits the site you can check to see if that IP address is in the table or not.. If the address is in the table do nothing if it is not in the table add it.. then to get the total visitors you simply count() the number of rows in that table.. Something like this.. // Do the checking and inserting // $sql = "SELECT ip_address from visitors WHERE ip_address = $usersIP"; $sql_query = mysql_query($sql) or trigger_error(mysql_error()); if (mysql_num_rows($sql_query) == 0) { mysql_query("INSERT INTO visitors SET ip_address = $usersIP"); } // Counting $sql = "SELECT COUNT(ip_address) as `count` FROM visitors"; $sql_query = mysql_query($sql) or trigger_error(mysql_error()); $data = mysql_fetch_assoc($sql_query); echo 'Number of Unique Visitors: ' . $data['count']; ?> Or something like that. Could be better but its a start for you. Quote Link to comment Share on other sites More sharing options...
corrupshun Posted February 7, 2010 Author Share Posted February 7, 2010 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.