in several ways.
First you can create an index in your table. (as an example, I use just a table).
CREATE TABLE `test` ( `id` INT NOT NULL , `name` VARCHAR( 255 ) NOT NULL , `date` DATE NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM; ALTER TABLE `test` ADD UNIQUE ( `name` , `date` );
This is the MySQL way.
You should also do checks in PHP, although you can do this on insert (MySQL will return an error, and you can check it). But you can do an extra SELECT before inserting ( SELECT * from test WHERE name=USER AND date=DATE ) and check the number of records. If it is greater than 0, you are showing an error.
When saving, you rarely have to worry about one additional SQL. If you need to, just check the MySQL statement for errors (MySQL path :)).
Tomasz StruczyΕski
source share