in reply to [OT] Database Design

CREATE TABLE `languages` ( `lang_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `lang_name` VARCHAR(60) NOT NULL ); CREATE TABLE `post_translations` ( `post_translation_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRI +MARY KEY, `post_translation_cat` INT(11) UNSIGNED NOT NULL, `post_translation_date` DATETIME NOT NULL, `post_translation_title` VARCHAR(255) NOT NULL, `post_translation_body` TEXT NOT NULL, `post_translation_lang` TINYINT UNSIGNED NOT NULL ); CREATE TABLE `posts` ( `post_id`, INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `post_translation_id` INT(11) UNSIGNED NOT NULL, );

For each post, you'll have multiple translations. All you have to do now is to find the correct translation for the current post_id.

Replies are listed 'Best First'.
Re^2: [OT] Database Design
by Anonymous Monk on Aug 11, 2010 at 02:58 UTC

    I could not understand how this works? would you mind explain it to me?

    How would I use the `post` table with an auto_increment field `post_id` and only 1 field `post_translation_id` to have more than one translation per post?

    Thanks for your help

      If someone wants to read post $post_id in language $language_name,
      my $sth = $dbh->prepare(' SELECT * FROM post_translations JOIN posts ON post_translations.post_translation_id = posts.post_translati +on_id JOIN languages ON post_translations.lang_id = languages.lang_id WHERE posts.post_id = ? AND languages.lang_name = ? '); $sth->execute($post_id, $language_name);

      Pardon any syntax errors.

      How would I use the `post` table with an auto_increment field `post_id` and only 1 field `post_translation_id` to have more than one translation per post?

      You woulnd't. You'd fix my bug :)

      If you wanted to have it autoincrement,

      CREATE TABLE `languages` ( `lang_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `lang_name` VARCHAR(60) NOT NULL ); CREATE TABLE `post_translations` ( `post_translation_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRI +MARY KEY, `post_translation_cat` INT(11) UNSIGNED NOT NULL, `post_translation_date` DATETIME NOT NULL, `post_translation_title` VARCHAR(255) NOT NULL, `post_translation_body` TEXT NOT NULL, `post_translation_lang` TINYINT UNSIGNED NOT NULL ); CREATE TABLE `posts` ( `post_id`, INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, ); CREATE TABLE `post_to_translation` ( `post_id`, INT(11) UNSIGNED NOT NULL, `post_translation_id` INT(11) UNSIGNED NOT NULL, );

      Update: Since it's an 1:N and not N:N relationship, post_to_translation is not necessary.

      CREATE TABLE `languages` ( `lang_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `lang_name` VARCHAR(60) NOT NULL ); CREATE TABLE `post_translations` ( `post_id`, INT(11) UNSIGNED NOT NULL, `post_translation_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRI +MARY KEY, `post_translation_cat` INT(11) UNSIGNED NOT NULL, `post_translation_date` DATETIME NOT NULL, `post_translation_title` VARCHAR(255) NOT NULL, `post_translation_body` TEXT NOT NULL, `post_translation_lang` TINYINT UNSIGNED NOT NULL ); CREATE TABLE `posts` ( `post_id`, INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, );
Re^2: [OT] Database Design
by xiaoyafeng (Deacon) on Aug 11, 2010 at 09:50 UTC

    ikegami ++!

    this is the best way for multi-language design.




    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction