Set session - Multi Language

Hi Folks…another question…:blush:

How do i set a session value for the website language? Well, really its in two parts, set the default language ‘Italian’ and also add the session code to two buttons (italian and english), so when pressed, checks present laguage and if change, the same page will refresh with the other language.

The text is in a database with this structure;

ID…pageid…lang…text
1…1…eng…‘english text’
2…1…it…‘italian text’

…the second part of the question, how do i retrieve the record with the session? Something like;

SELECT content.ID, content.pageid, content.lang, content.text
FROM content
WHERE content.pageid = 1 AND content.lang =$session

…sorry, i dont have any brains this morning!

Thanks in advance


$_SESSION['Lang'] = 'en';

That should do it if I understand you correctly.:slight_smile:

ok, ive had a little rethink and looked around…does the following look ok?


Content_en
  Pageid        | Title              |  maintext
    1             | English title1   | English text
    2             | English title2    | English text


the to pull down the records i could use;

$suffix = mysql_escape_string($_SESSION['lang']);
$query = "SELECT * FROM `content_".$suffix."` WHERE `page`='pagename';";

and the top of each page i would have;

<?php
SESSION_START();
if (isset($_GET['lang'])) {
	$lang=$_GET['lang'];
	$_SESSION['lang'] = $lang;
}
if(!isset($_SESSION['lang'])){
	$lang="it";
}else{
	$lang = $_SESSION['lang'];
}
?>

…does this look ok so far?

The last bit, what script do i add to a button to check the laguage, and if change, refresh the same page, but with the correct language?

just a gentle bump :slight_smile:

hi, if that’s how you want to do it, then post the form on the same page, pull the correct page from the db and then redirect to that page :slight_smile:

well, the reason for the post is to script the language button correctly, so that i t checks the present session langauge, and if differant, reloads the same page with the new language…

hum…i making too many mistakes…

I use dreamweaver a little…what i have is

<?php

session_start();

if (isset($_GET['lang'])) {

    $lang=$_GET['lang'];

    $_SESSION['lang'] = $lang;

}

if(!isset($_SESSION['lang'])){

    $lang="en";

}else{

    $lang = $_SESSION['lang'];

}

?>
<?php
mysql_select_db($database_valianilocal, $valianilocal);
$suffix = mysql_escape_string($_SESSION['lang']);
$query_Recordset1 = "SELECT * FROM 'home1_".$suffix."' WHERE id = 1 ";
$Recordset1 = mysql_query($query_Recordset1, $valianilocal) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

however i get an error near ‘‘home1_’ WHERE id = 1’

…any advise

just a gentle bump:)