如何选择外语的mysql查询? [英] how to select mysql query with foreign language?

查看:60
本文介绍了如何选择外语的mysql查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我以简单的方式向您展示

Let me show you in simple way

 SELECT * FROM dictionary WHERE malayalam = 'ആകാശം'

此查询可同时在phpmysql上正常工作,而在.php页面上查询时未检测到原始数据

this query working fine on phpmysql at the same time it doesn't detect raw while query on .php page

我只是在建立英语对马拉雅拉姆语和马拉雅拉姆语对英语词典

I am just building a English to Malayalam and Malayalam to English dictionary

该网站为 http://www.chatfitness.com/

从mysql接收到的malayalam单词可以在英语单词的基础上很好地工作.

receiving malayalam word from mysql working fine on the basis of English word.

不幸的是,收到的英语单词无法正常使用:(

unfortunately receiving English word doesn't work properly :(

我对两个函数使用相同的查询 这是用英文单词搜索的代码

I'm using same query for both function here is the code searching with English word

if(isset($_GET['en']))
{
    $english = $_GET['en'];
    mysql_query ("set character_set_results='utf8'"); 
    $result=mysql_query("SELECT * FROM en_table WHERE word = '$english' LIMIT 1"); 
    $numrows=mysql_num_rows($result);

    if($numrows!=0){
        $row = mysql_fetch_array($result);
        $english_id = $row['en_id'];

        //select malayalam id which are matching with english id
        $en_query = mysql_query("SELECT * FROM dictionary WHERE english = '$english_id'"); 
        //$en_rows = mysql_fetch_array($en_query);

        while($en_rows = mysql_fetch_array($en_query)){
        $en_malayalam = $en_rows['malayalam'];
        mysql_query ("set character_set_results='utf8'");
            $ml_query=mysql_query("SELECT * FROM ml_table WHERE ml_id = '$en_malayalam'");
            while($ml_rows = mysql_fetch_array($ml_query)){
            echo $ml_rows['word'];
            echo "<br />";
            }

        }

    }else{
        echo "<p>നിങ്ങള്‍ അന്വേഷിക്കുന്ന " . $english . " എന്ന പദത്തിന്റെ അര്‍ഥം കണ്ടെത്താനായില്ല.</p> 
        <p>സാധ്യമെങ്കില്‍, ദയവായി നിഘണ്ടുവില്‍ ചേര്‍ക്കുക.</p>";
    }

使用与马拉雅拉姆语搜索相同的方式

the same way I'm using searching with Malayalam

}elseif(isset($_GET['ml'])){
    $malayalam = $_GET['ml'];
    mysql_query ("set character_set_results='utf8'");
    $results=mysql_query("SELECT * FROM ml_table WHERE 'word'= '$malayalam' LIMIT 1"); 

    $numrow=mysql_num_rows($results);
    echo $numrow ;

   //here is the problem $numrow always zero :( 
    if($numrow!=0){
        $row = mysql_fetch_array($results);
        $malayalam_id = $row['ml_id'];
        //echo $malayalam_id ;
        //select malayalam id which are matching with english id
        $ml_query = mysql_query("SELECT * FROM dictionary WHERE malayalam = '$malayalam_id'"); 
        //$en_rows = mysql_fetch_array($en_query);

        while($ml_rows = mysql_fetch_array($ml_query)){
        $ml_english = $ml_rows['malayalam'];            
            $ml_query=mysql_query("SELECT * FROM en_table WHERE en_id = '$ml_english'");
            while($ml_rows = mysql_fetch_array($ml_query)){
            //echo $ml_rows['word'];
            echo "<br />";
            }
        }    
    }else{
        echo "We do not have meaning of $malayalam at the moment. <br /> Could you add your word pls";
    }


}else{
    die("please select search value");
}

我从mysql搜索的内容$ numrow = mysql_num_rows($ results);数总是零:( 您能帮我解决这个问题

what ever I search from mysql $numrow=mysql_num_rows($results); numrows always zero :( could you help me please for this problem

我被困在这里:( 预先感谢

I'm stuck here :( thanks in advance

推荐答案

您应该尝试以下方法之一:

You should try one of these:

1.)使用mysql_set_charset('utf8', $dbconn);代替mysql_query(),如

1.) using mysql_set_charset('utf8', $dbconn); instead of mysql_query() as shown in http://php.net/manual/en/function.mysql-set-charset.php

2.)按照在MySQL中设置utf8的建议使用query("set names utf8");吗?

2.) use query("set names utf8"); as suggested in SET NAMES utf8 in MySQL?

这篇关于如何选择外语的mysql查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆