Make table with two record unique |
this is very simple.
this case call composite primary key. you can google for this. create new table tbl_user_product_relation sUsername Primary Key char(8) sProductID primary key int(11) sDatetime timestamp current_timestamp try to add entry directly from php myadmin sUsername : tony sProducID: 1 sUsername: tony sProductID: 2 sUsername: joe sProductID: 1 all above will successfull. and below will not allowed sUsername: tony sProductID: 1 this is what do you want, right? in PHP you need to check this select * from tbl_user_product_relation where sUsername=? and sProductID=? if num_rows() == 1 Insert else echo 'duplicate' NOTE: Quote:hei.. what about my sID? you dont need that. What you know about table is: every table must have id as primary key and auto_increment Nooooo... that's totally wrong. and if you pretend to not remove sID, you will have 3 composite primary key, and you will always have duplicate possibility, because: sID sUsername sProductID 1 tony 1 2 tony 1 3 tony 1 100 tony 1 is different |
Messages In This Thread |
Make table with two record unique - by omid_student - 12-16-2017, 12:03 PM
RE: Make table with two record unique - by plonknimbuzz - 12-16-2017, 10:58 PM
RE: Make table with two record unique - by omid_student - 12-17-2017, 01:49 AM
RE: Make table with two record unique - by omid_student - 12-17-2017, 01:53 AM
RE: Make table with two record unique - by plonknimbuzz - 12-20-2017, 12:39 PM
|