Andre Polykanine Insert only if the entry doesn't exist
Feb 14, 2011; 20:12
Andre Polykanine
Insert only if the entry doesn't exist
Hi all, Thanks for your fast answer to my last question! Here's one more problem I commonly deal with. There are cases when I need to insert the row only if such a row doesn't exist, otherwise I need either to update the row or to do nothing, just skip the query. The common case is the rating increment/decrement. I have the + and - links which are AJAX. So I need to prevent fast multiple clicking and over-increasing or over-decreasing the rating of the blog entry. Here's what I'm doing, in a simplified form (assume all of the numbers are PHP variables): "SELECT `Id` FROM `Votes` WHERE `EntryId`='12345' AND `UserId`='789'"; then I'm checking if the user has already clicked a link: if (mysql_num_rows()==0) { "INSERT INTO `Votes` SET `EntryId`='12345', `UserId`='789'"; } else { // do nothing }
And here is the question (at last!): How can I MySql'ly check whether a vote does exist and if it does, then insert the row, else either do nothing or update several columns? I assume I can't use ON DUPLICATE KEY UPDATE because I have no unique keys... Hope you understood my problem). Thanks!
-- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=listsearcharchive@lassosoft.com
Feb 14
Jo?o C?ndido de Souza Neto Re: Insert only if the entry doesn't exist
Feb 14, 2011; 16:38
Jo?o C?ndido de Souza Neto
Re: Insert only if the entry doesn't exist
Feb 14
Andre Polykanine Re: Insert only if the entry doesn't exist
Feb 14, 2011; 22:39
Andre Polykanine
Re: Insert only if the entry doesn't exist
Feb 14
Rolando Edwards RE: Insert only if the entry doesn't exist
Feb 14, 2011; 16:01
Rolando Edwards
RE: Insert only if the entry doesn't exist
Feb 15
Andre Polykanine Re: Insert only if the entry doesn't exist
Feb 15, 2011; 02:14
Andre Polykanine
Re: Insert only if the entry doesn't exist
Feb 15
Joerg Bruehe Re: Insert only if the entry doesn't exist
Feb 15, 2011; 19:58
Joerg Bruehe
Re: Insert only if the entry doesn't exist
Feb 14
Rolando Edwards RE: Insert only if the entry doesn't exist
Feb 14, 2011; 15:33
Rolando Edwards
RE: Insert only if the entry doesn't exist
Search
Lasso Programming
This site manages and broadcasts several email lists pertaining to Lasso Programming and technologies related and used by Lasso developers. Sign up today!