Insert data into several fields alike!?!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Insert data into several fields alike!?!

Post 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!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Insert data into several fields alike!?!

Post 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");
Post Reply