I am having trouble understanding how do this. commentid is an id of a row in the comment table. The vote table has three columns: id, commentid & username.
What i want is to insert into the vote table only if the last two columns(commentid and username) doesn’t exist. $commentids is an array of multiple $id from the comment table. How do i add a unique index to accomplish this?
$commentids = explode(".",$id);
foreach($commentids as $value) {
$insert = mysql_query("INSERT IGNORE INTO vote
(id, commentid, username)
VALUES
('','$value','$username')", $this->connect);
}
If you want the
(commentid,username)pair to be unique then:If you want each of
commentidandusernameto be globally unique within the table then: