I am not an expert in PHP/MySql so my first idea about how to handle a website with multiple languages and making the PHP code readable was the following:
1) Creating a table with "word, en, it, de, fr" fields, one for each string I want to be translated. For example:
WORD EN IT DE FR
title HomePage Pagina No Idea
thanks Thank You Grazie Danke Merci
2) Storing the table in an array of array of strings, so that I could access it in this way:
print $word["thanks"]["it"];
which IMHO would make the PHP code very readable (performance is NOT IMPORTANT).
So, I wrote this code to read the data from the DB, and if the translation is empty, I fill the array with "the word in XX is missing" (to avoid pasting all the identical code, I am only showing you one case):
$s = "SELECT word, it, en, de, fr FROM languages";
$result = $conn->query($s);
while ($r = $result->fetch_array(MYSQLI_ASSOC)) {
$word = $r["word"];
$it = $r["it"];
// and DE and EN and FR...
if ($it != "")
$w["$word"]["$it"] = $it;
else
$w["$word"]["$it"] = $word." IT missing";
// and DE and EN and FR...
}
I tried putting the double quotes, I tried removing them... But every time I print the $w variable, is ALWAYS empty. The intermediate variables read from the DB look ok.
What am I doing wrong? Thank you.
while
loop? – u_mulder Aug 2 '15 at 17:00"$word"
and"$it"
. – Jessica Aug 2 '15 at 17:03var_dump($r)
-what it shows? – u_mulder Aug 2 '15 at 17:04var_dump($r)
afterwhile ($r = $result->fetch_array(MYSQLI_ASSOC)) {
- what do you see? – Jessica Aug 2 '15 at 17:04