Jump to content

Recommended Posts

I would like to update a table or insert if a specific combination of indices do not already exist. The table is very simple.

 

CREATE TABLE `sessProdLnk` ( `products_id` varchar(20) NOT NULL, `sessions_id` varchar(255) NOT NULL, `qty` int(6) NOT NULL, KEY `products_id` (`products_id`), KEY `sessions_id` (`sessions_id`) ENGINE=MyISAM DEFAULT CHARSET=latin1

 

So, I would like to search for a match between my data, and any row in sessProdLnk where both the sessions_id and products_id match. Then I would like to update any entries in qty where they match, and insert a new row for any data pairs that do not have matches.

 

I know some of this comparison may have to be done programmatically in the php script, but I am still getting to know MYSQL and was wondering how much of the work it will do for me given these parameters.

Edited by nodirtyrockstar
Link to comment
https://forums.phpfreaks.com/topic/269951-update-and-insert-help/
Share on other sites

I actually reexamined the architecture of the database. Essentially I had two fields that were not unique, but what would be unique is the combination of the two fields. I created another field which is a combination of the session ID and product ID. This creates a singular unique key and allows me to use the ON DUPLICATE KEY UPDATE command.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.