Ok, I am a real big nOOb at php. I am actually fighting my way through a script that I almost have the first beta version done. I am also currently working on the next version that will hopefully be multilingual which bring me to my problem:
The problem I am having is how do I get the visitor to choose there language for viewing.
Here is my current code:
get_language.php
<?
// mysql
include "inc/dbinfo.inc.php";
$connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbname");
$sql1 = mysql_query("SELECT lang from variables") or die(mysql_error());
while($row1 = mysql_fetch_array($sql1))
{
$newlang = $row1['lang'];
}
if (empty($_SESSION['language']['lid'])) {
$_SESSION['language']['lid'] = $newlang;
}
// mysql
include "inc/dbinfo.inc.php";
$cnn = mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
if (!$cnn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("$dbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
//your query (if it's okay; check it with echo command - echo $sql to see if it's good)
$sql = "SELECT * FROM languages WHERE lid = " . $_SESSION['language']['lid'];
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result)) {
$path = $row['lpath'];
}
mysql_free_result($result);
?>
The first part of the code:
$sql1 = mysql_query("SELECT lang from variables") or die(mysql_error());
while($row1 = mysql_fetch_array($sql1))
{
$newlang = $row1['lang'];
}
if (empty($_SESSION['language']['lid'])) {
$_SESSION['language']['lid'] = $newlang;
}
Allows the admin to set the default lang to whatever they choose:
1 - english
2 - french
3 - spanish
etc...
The second part of the code:
index.php
include "./inc/get_language.php";
include "./lang/".$path."/main.lang.php";
etc...more php code here
I am lost as of here on how to do it the way I need it to. Does anybody have any ideas or able to direct me to some ideas on how to do this?
Thank you in advance.