php mysql check existing syntax -


i have ordering system 1 6 (both inclusive), order number assigned news in table featured user's choice. when user saves order news, in table featured inserted new row these fields: id_news, id_user, id_category , order

what looking better syntax check if there news client x order y.

right i'm doing each thing in separate query, these actions:

  1. user chooses feature news 1241 order number 3
  2. script checks see if there exists news client x order number 3
  3. if exists, deletes it
  4. add new featured news.

anyway of making in less actions/code?

use on duplicate key update.

assuming (id_user,order) unique key, can insert new value and, if order exists, update new id_news.

insert `featured` values (...) on duplicate key update `id_news`=values(`id_news`) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -