I have two tables related to categories. One is called category_list which is mainly for administration purpose:
CREATE TABLE IF NOT EXISTS `category_list` (
`category_id` tinyint(2) NOT NULL auto_increment,
`category` varchar(32) default NULL,
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and a table categories, holding the different categories in 6 different languages:
CREATE TABLE IF NOT EXISTS `categories` (
`cat_id` tinyint(2) NOT NULL auto_increment,
`category_id` tinyint(2) NOT NULL,
`language_abbr` char(3) NOT NULL,
`category_name` varchar(32) NOT NULL,
PRIMARY KEY (`cat_id`),
FOREIGN KEY (`category_id`) REFERENCES `category_list` (`category_id`) ON DELETE CASCADE,
FOREIGN KEY (`language_abbr`) REFERENCES `languages` (`language_abbr`) ON DELETE CASCADE,
KEY `category_name` (`category_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
So doing an insert goes in two steps. The first insert in to the table category_list and after that into the table categories, but I can’t figure out how to get the six different values for the six text fields(languages) in the database since they have a different name in the form, where in the database there is just one field (category_name). Everything goes well with the category_id and language_abbr by using the id from the first insert and using the table languages to get the active languages:
INSERT INTO
categories
(
category_id
, language_abbr
)
SELECT
#catID#
, language_abbr
FROM
languages
WHERE
language_isActive IN ( 1 )
Unfortunately a can’t give those textfields the same name like with a check box group. Any ideas?
Hi Rudy. I use the two different tables since the categories are part of the menu and because i’m working with different languages. This way when from the menu I redirect to the activities page the activity_id is always the same, no matter from which language I’m coming. The problem I have is populating the category_name. Since there is just one name in the database, but I have obviously six different form names (cat_eng, cat_gre, cat_rus, cat_dut, cat_fre, cat_swe)
Hi Rudy, I thought it could be done in just one go. The way I have it now, with the category_id and language_abbr there are indeed 6 rows inserted at the same time!