我有一个多语言网站,并使用它来获取用户使用的语言:
$languagestring = array();
$res1 = "SELECT id, text FROM ".$prefix."_language WHERE lang = 'en' ORDER BY id ASC";
if($result1 = $mysqli->query($res1)){
while($row1 = $result1->fetch_object()){
$langid = $row1->id;
$res = "SELECT text FROM ".$prefix."_language WHERE fk_id = $langid AND lang = '$language'";
if($result = $mysqli->query($res)){
$row = $result->fetch_object();
if(!$row){
$languagestring[] = $row1->text;
} else {
$str = $row->text;
$languagestring[] = $str;
}
}
}
}
在这个脚本中,我首先获取默认的英语语言,然后检查用户喜欢的语言是否有与英语匹配的字符串。这就像一个魅力,但执行时间很长。是否可以将这两个查询合并为一个,如果是的话......如何?
提前致谢 ;-)
######## 编辑试过这个没有运气:
$res1 = "SELECT t1.text as etext, t2.text
FROM ".$prefix."_language t1 LEFT JOIN ".$prefix."_language t2 ON t2.fk_id = t1.id AND lang = 'da'";
if($result1 = $mysqli->query($res1)){
while($row1 = $result1->fetch_object()){
$row1->text.'<br>';
}
}
它不会返回任何结果?