MySQL and PHP newbie here.
Here’s a description of my issue:
I have a table called “Items”. The primary key column for this table is “item_id”
I have a table called “Images”.
“Images” contains a column named “image_item_id” This contains a value that links the image to the “item_id” in the “Items” table.
“Images” contains a column named “image_type”. The value of type will be either “main” or “secondary”.
I only ever want 1 instance of “main” to associated with “image_item_id”. All other instances are to be “secondary”.
I’m not sure how to go about doing this, or even if it is possible.
I’m guessing that if I do this with PHP, then when I add an image with a “image_type” value of “main”, then I would have code that would check all other instances of the matching “image_item_id”, and if their values are “main”, then change them to “secondary”?
I think I have the knowledge to create the code for this, but before I start fumbling my way to make the code, I just wanted to check if there was a better way to do this (either through PHP or with the settings of the MySQL table).