i'm working on a website where i select some text from DB according to the language selected:

Here's where i define the language (where default = 'pt'):

$lang = array('pt', 'en');

//iniciar sessao -> array

//verificar var lang no url -> pagina.php?lang=pt
if(isset($_GET['lang']) && in_array($_GET['lang'], $lang))
    $_SESSION['lang'] = $_GET['lang'];
    $_SESSION['lang'] = 'pt';

//incluir a linguagem
if(isset($_SESSION['lang']) && in_array($_SESSION['lang'], $lang))
    require_once 'lang_'.$_SESSION['lang'].'.php';

And here is where i'm selecting the text:


include 'common.php';
include 'db_connect.php';

if (isset($_GET['lang']))
    $sel_lang="SELECT * FROM content_lang WHERE lang='".$_GET['lang']."'";
    $language=mysql_query($sel_lang, $connect);

    $sel_text="SELECT * FROM content_lang WHERE titulo='Family Office' AND lang='".$row_lang['lang']."'";
    $text=mysql_query($sel_text, $connect);

<span class="fontchange"> <?php echo $row_text['titulo'];?> </span>
<?php echo $row_text['descricao']; ?>

    $title="Familly Office";
    include 'include/master.php';

I want to say that if lang = default the text is portuguese (pt).

Can someone help me?

Thank you,

Member Avatar

You need to include the first snippet in every page.

I don't understand why you're duplicating code in the second snippet. You should already have your language in the $_SESSION['lang'] variable. If you've included the first snippet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.