Page 1 of 1

Insert data into several fields alike!?!

Posted: Wed Mar 26, 2008 10:44 am
by jmansa
I'm trying to make a script where I want to put the same data into several of fields which only have the end of the fieldname different depending on language.

My fileds look like this:

headline_en, headline_fr, headline_de.

As you can see it is only the language extension wich is different, and would be farely simple to just tell the script to put data into these fields... but... If I would decide later on to make a new country I would have to go into the script and add this field... Isn't it possible to only tell it once that it is the headline_(?) or something... Hope this is understandable and can be done.

Please help!

Re: Insert data into several fields alike!?!

Posted: Wed Mar 26, 2008 10:52 am
by onion2k
Now would be a good time to rethink your database structure. Having 1 row per language would be a lot more sensible, and a lot easier to edit. You'd need 3 tables ... one for the thing (articles for example), one for languages, and one for the actual data Eg, if 1 is English, and 2 is French...

Code: Select all

INSERT INTO `article` 
(article_id, reference)
VALUES
(1, "article1");
 
INSERT INTO `language` 
(language_id, title)
VALUES
(1, "English"),
(2, "French");
 
INSERT INTO `data` 
(article_id, language_id, headline, article)
VALUES
(1, 1, "Everything is fine", "Everything is fine and well today");
 
INSERT INTO `data` 
(article_id, language_id, headline, article)
VALUES
(1, 2, "Tout est parfait", "Tout est parfait et bien aujourd'hui");