Jump to content

Recommended Posts

hello, I have a script that helps me manage my site. I've coded it from the ground up and everything works fine. Now I'm just looking to tweak things so it'll work to my advantage more. This is what I'm triyng to do. I have an id that is used in one table (for my categories)... and this ID is used in another table (for my articles). Now when I edit a category ID how would I go about updating the ID on the other table? I would search google but I'm not sure what to look for? Does anyone know any good tutorials or terms I can search for to accomplish this?

Link to comment
https://forums.phpfreaks.com/topic/176665-updating-something-in-php-and-mysql/
Share on other sites

Well firstly I really don't see a reason why you should need to update an ID. The whole point of an ID is that it uniquely identifies a row. If for some reason this was a requirement (I can't think of a valid one, but maybe you can prove me wrong), I guess you would have to update links to the ID before updating the ID using an UPDATE table SET cat_id=$new_id WHERE cat_id=$old_id.

If you are using the InnoDB Storage Engine, you should define the ID in the articles table as a Foreign Key to the Catagories table.  Part of the FKey definition is how to handle DELETES or UPDATES of the key.  ON UPDATE CASCADE should cause the ID to be updated in the "foreign" table (Articles) when you update the ID in the Categories table.

 

 

I understand the concept of an ID being uinuqe. All I want to know is how I would go about editing the ID field in one table, after the id is edited in another. From what I can tell "UPDATE table SET cat_id=$new_id WHERE cat_id=$old_id" will change it for me? Seems like it would do what I'm asking, I'll get back and let you know. Thanks for the suggestions and advice!

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.