following problem: I want to build a mysql based language system.
To decrease loading time and increase performance I thought it would be the best, to first fetch all Language phrases into an array (which happens with mysqli fetch array). Then, if a language term is required, calling a function with the array as global variable.
My function for the array:
$sql = $db->query('SELECT * FROM lang_phrases WHERE phraseLanguageId = 1');
$phrases = array();
while($row = $sql->fetch_array()) {
$phrases[] = $row;
}
Now I've got this array:
array(2) {
[0]=> array(8) {
[0]=> string(1) "1"
["phraseId"]=> string(1) "1"
[1]=> string(1) "1"
["phraseLanguageId"]=> string(1) "1"
[2]=> string(4) "HOME"
["phraseKey"]=> string(4) "HOME"
[3]=> string(10) "Homepage"
["phraseContent"]=> string(10) "Homepage"
}
[1]=> array(8) {
[0]=> string(1) "2"
["phraseId"]=> string(1) "2"
[1]=> string(1) "1"
["phraseLanguageId"]=> string(1) "1"
[2]=> string(4) "BACK"
["phraseKey"]=> string(4) "BACK"
[3]=> string(6) "Back"
["phraseContent"]=> string(6) "Back"
}
}
And thats my function:
function l($key) {
global $phrases;
return PLACEHOLDER;
}
I wonder, how can I now search the array for "phraseKey" $key from the function and get the value? Do you have any hints? Or shall I simply select each phrase with each one query (performance problems with 100 quers per load?!)?
Cheers and Thanks!