Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:32:12+00:00 2026-05-23T01:32:12+00:00

Using PHP 5.x and MySQL 5.x So I asked a question yesterday about the

  • 0

Using PHP 5.x and MySQL 5.x

So I asked a question yesterday about the best way of handling dynamic data in multilanguage, this question is what would be a good solution for the database structure to handle this. I have entries in the database for things like stories. My plan is to store a different version of the story for each language available in a db. So if the site supports english and spanish then in the admin tool they can add a english version of a story and a spanish version of a story.

My thoughts on that was to have seperate tables in the db, one for each language. So one story table for english version, one for spanish and one for whatever other languages. Then on the front end I simply allow the visitor to select what language to view the site in and via variables know what table to query to get that version of the story. But one issue is what if there isnt a spanish version but they selected spanish? Is that a good solution or is there a better way of doing this? Looking for suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:32:13+00:00Added an answer on May 23, 2026 at 1:32 am

    Having multiple tables is really not necessary, unless you plan on having millions of stories… I usually go along with two tables; one for the item and another for the localized item

    For example, a story would be like

    table “story”

    id INTEGER (Primary Key)
    creation_date DATE_TIME
    author VAR_CHAR(32)
    ..other general columns..
    

    table “story_localized”

    story_id INTEGER (Foreign Key of story.id) \
    lang CHAR(2)                               -- (Indexed, unique -- story_id+lang)
    content TEXT
    ..other localized columns..
    

    Performing the query is simply a matter of JOINing the two tables :

    SELECT s.*, sl.*
      FROM story s
      JOIN story_localized sl ON s.id = sl.story_id
     WHERE s.id = 1         -- the story you're looking for here
       AND sl.lang = 'en'   -- your language here
       -- other conditions here
    

    This configuration gives a few advantages :

    • all your data is in the same table, no need to synchronizing CRUD operations
    • you can add new languages to any story without the need to create yet more tables
    • etc.

    ** EDIT **

    Just as a bonus, here is a “trick” to retrieve a story easily, regardless of the language it’s been written into

    SELECT *
      FROM (SELECT * 
              FROM story s
              JOIN story_localized sl ON s.id = sl.story_id
             WHERE s.id = {storyId}
               AND sl.lang = {desiredLanguage}    -- example : 'es'
            UNION
            SELECT * 
              FROM story s
              JOIN story_localized sl ON s.id = sl.story_id
             WHERE s.id = {storyId}
               AND sl.lang = {defaultLanguage}    -- example : 'en'
            UNION
            SELECT * 
              FROM story s
              JOIN story_localized sl ON s.id = sl.story_id
             WHERE s.id = {storyId}
             LIMIT 1                              -- ..get the first language found
    ) story_l
    LIMIT 1              -- only get the first SELECTed row found
    

    Will try to fetch the story in the {desiredLanguage}, if the story is not available in that language, try to find it in {defaultLanguage} (ie. the site’s default language), and if still nothing found, it doesn’t matter which language to fetch the story, then, so fetch the first one found. All in one query, and all you need are 3 arguments: the story id, the desired language, and a default fallback language.

    Also, you can easily find out in what language the story is available into with a simple query :

    SELECT sl.lang
      FROM story_localized sl
     WHERE sl.story_id = {storyId}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a wepage in php using MySQL as my database. Which way is
I've been using PHP & MySQL for ages and am about to start using
I asked a question yesterday about password safety... I am new at security... I
I've got a simple website using plain HTML/CSS to display and PHP/MySQL for data
This is language agnostic (but I am using PHP and MySQL if it helps).
Been using PHP/MySQL for a little while now, and I'm wondering if there are
Using PHP and MySQL, I have a forum system I'm trying to build. What
I'm planning to make a very simple program using php and mySQL. The main
I am part of a team creating a web application using PHP and MySQL.
I am part of a team creating a web application using PHP and MySQL.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.