Check if Table Entry Exists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jesse B
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2010 9:44 pm

Check if Table Entry Exists

Post by Jesse B »

This seemed to be a very simple thing to do at first, but is proving to be more difficult than I originally imagined. I'm sure it's quite simple, I just can't quite figure it out. Every piece of code I've tried doesn't quite work properly. Anyways, I digress.

This is for an updating script that I wrote, which does a recursive scan and if it's a file, adds it's Path, Name, and Extension to a mySQL Table. Right now I've got it so it uploads an entry for each file, but if I run it again it adds a duplicate entry. I don't want to just wipe the table each time, as I'd like for the ID# in the table to remain the same.

Anyways, any suggestions? If you want my current code just lemme know and I'll post it.

Thanks,


- Jesse
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Check if Table Entry Exists

Post by requinix »

Make the path+name+extension a unique key and use an INSERT IGNORE query.
Jesse B
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2010 9:44 pm

Re: Check if Table Entry Exists

Post by Jesse B »

I'll try that out, thanks.
Post Reply