用字符串来设置语言

时间:2015-04-14 12:21:40

标签: php while-loop multiple-languages

  $no = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
  while($n = mysql_fetch_array($no)){
     $message = $n['message_RS'];

     if(strlen($message) > 50){ 
          $message = substr($message,0,50); 
          $message .= "..."; 
     }   

      echo " <div class='text'> <p> <a href='#'>$n[title]</a> <br /> <small>$message</small> </p> </div> ";
  }

排队:

$message = $n['message_ HERE GOING LANGUAGE'];
Language = $_COOKIE['language'];

我只需要从表中为选择的语言获取任何帮助

2 个答案:

答案 0 :(得分:0)

$message = $n['message_' . $_COOKIE['language']];

答案 1 :(得分:0)

  $no = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
  while($n = mysql_fetch_array($no)){

     // lang
     $lang = $_COOKIE['language'];
     if($lang == "en"){
         $lang = "EN";
     } else if($lang == "srb"){
         $lang = "RS";
     } else if($lang == "ru"){
         $lang = "RU";
     }

     $message = $n['message_'.$lang];

     if(strlen($message) > 50){ 
          $message = substr($message,0,50); 
          $message .= "..."; 
     }   


      echo " <div class='text'> <p> <a href='#'>$n[title]</a> <br /> <small>$message</small> </p> </div> ";
  }