You can add a unique index to your URL column which will then only allow unique values to be inserted. Then you have 2 options: 1) you can either query the database first to see if it contains the URL you will be attempting to insert or 2) you can just insert each time and catch the error that MySQL will produce if it already contains that URL.
Myself, I would choose option number 2. This way you aren't wasting time or effort querying the database first and your guaranteed that you won't have duplicate values.
-Pat
Main Topics
Browse All Topics





by: theandrewPosted on 2004-09-11 at 12:27:49ID: 12035487
I have a script that does this.
Here are two ways of doing it:
1) First, do a DELETE in the database, to delete all of the records from the database that match that IP and that URL. Then do your insert. If you have a date field you will be able to see the last date/time that they were at that page.
2) Insert it anyways, leave the duplicates there (nice later for detailed reporting). Adjust your script for reporting the number of hits or whatever to: SELECT DISTINCT IP,URL FROM........ this will only pull the unique ip and url page combinations and wont show the duplicates.
Additionally:
If you did a SELECT URL,IP,COUNT(IP) AS COUNT from table GROUP BY IP,URL......
This would show you a count of how many times that person has viewed that page.
If you post your actual table names and fields i can spell out the exact code for ya.