0

I have a script that displays countries in different languages. For example "United Kingdom" in Spanish would be "Reino Unido", etc. Every language is stored in a different table, like "name_es" for Spanish or "name_en" for English. The correct table is then selected through a session value stored for each user. What I have is this:

    if ($countries_id)
    {
        $sql_select_countries = $this->query_silent("SELECT name_".$_SESSION['language']." as name FROM " . DB_PREFIX . "countries WHERE
            id IN (" . $countries_id . ")");

        if ($sql_select_countries)
        {
            while ($country_details = $this->fetch_array($sql_select_countries))
            {   
                $countries_array[] = $country_details['name'];
            }
        }
    }

Note that the problem line is this:

$countries_array[] = $country_details['name'];

I need it to be something like

$countries_array[] = $country_details['name_$_SESSION['language']'];

But I can't figure out the correct syntax :(

1
  • query_silent() - I like the name! Commented Mar 25, 2012 at 16:09

2 Answers 2

1

So you want to concatenate the string 'name_' with the vale stored in session?

$countries_array[] = $country_details['name_'.$_SESSION['language']];

I think if you add some speech marks and curly brackets you can do this:

$countries_array[] = $country_details["name_{$_SESSION['language']}"];
Sign up to request clarification or add additional context in comments.

Comments

0
$countries_array[] = $country_details[$_SESSION["language"]];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.