[Some Help] Telling PHP to identify pre-existing URLS.
I would like some help trying to code a little script. However, I do not want you guys to do it for me, simply direct me to a source where I can learn myself. I appreciate it in advanced.
Here is my problem:
- I would like to create a little script that will let users submit URLS and store them on a MYSQL database. When they log back into their account they will have the URLS displayed for them. Now, here is the thing I would like the submit feature to do. When they go to submit more URLS, I would like PHP to tell the user that they have submitted that specific URL already, and have it display the URL that is doubled.
If possible I would like them to be able to submit some URLS, and have php check them, and delete double URLS while it's being submitted and processed to the MYSQL table.
Thank you again, I would like to learn! So if anyone could link me a source where I can do this I'd appreciate it fully.
Assuming you are running a many to one (ie: replicated URL's are allowed since if you had two people with the same URL that doesn't mean that one won't delete or modify it and you don't want it to change both user's), then stopping it is a simple matter of using the INSERT IGNORE syntax. That is, after being given 100 records for example, if it finds 3 that are duplicates it will reject these three silently and continue with insertion instead of failing.
If the record is already saved, you can issue a SELECT first. I don't recommend doing that if you are using a batch insertion though as that will really cause a lot of overhead.
If its not yet saved, you can detect duplicates by using array_count_values. This creates an indexed 'value' as the key, and the value is the number of times that appears. If its > 1, then you have duplicates.
IMO, these can all be successfully ignored without even notifying the user. Simply removing them is sufficient.