Reputation: 2432
This is my existing MySql table
------ ------
c_id d_id
------ ------
C1 20
D2 21
D3 22
C2 22
D1 21
Then 2 new
entries will happen
C3 22
D1 33
Here based on d_id
, new entry 33
which is unique has been added. How do i know new value has been added, ignoring the duplicates.
My Query
$sql = "SELECT DISTINCT d_id FROM tablename GROUP BY d_id";
After getting unique d_id's
how to find newly added d_id
?
Upvotes: 1
Views: 1639
Reputation: 3425
Check the new value before inserting to table.
Do like this:
$sql = "SELECT * FROM tablename WHERE d_id = 33";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0){
// Insert
}else{
// Not Insert
}
Let me know for further help.
Upvotes: 1