4

Let me show you in simple way

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

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

the website is http://www.chatfitness.com/

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");
}

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

Community
  • 1
  • 1
Mo.
  • 26,306
  • 36
  • 159
  • 225
  • 3
    Try `mysql_error` after `mysql_query` and get error, then fix it. – Fedya Skitsko Feb 07 '12 at 11:16
  • @FedyaSkitsko When use SELECT * FROM dictionary WHERE malayalam = 'ആകാശം' result is zero at the same time when I use the same code phpmyadmin mysql like this SELECT * FROM dictionary WHERE malayalam = 'ആകാശം result it fine unfortunately it doesn't show result in php – Mo. Feb 07 '12 at 11:20
  • @FedyaSkitsko I mean it couldn't have error. Don't detect the row :( – Mo. Feb 07 '12 at 11:27
  • Your code is wide open to SQL injection attacks. Never use user-supplied inout without validating it and escaping it. – GordonM Feb 07 '12 at 11:42
  • @GordonM actually my problem is simple. I just edited question at the top. I tried many way, unfortunately I'm failed :( – Mo. Feb 07 '12 at 11:53
  • If you need to search in malayalam then first check your table charecter encoding. I think you have to change that to search malayalam. – PHP Connect Feb 07 '12 at 12:35

1 Answers1

4

You should try one of these:

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.) use query("set names utf8"); as suggested in SET NAMES utf8 in MySQL?

Community
  • 1
  • 1
Alfabravo
  • 7,493
  • 6
  • 46
  • 82
  • I tried both, but Korean is outputed as ud638\ud638\ud638\ud558\ud558\ud558\ud558 still. Are there other solutions? – coolcool1994 Aug 12 '13 at 08:31
  • @coolcool1994 look at this http://stackoverflow.com/questions/11182047/insert-korean-characters-to-mysql – Alfabravo Aug 12 '13 at 16:19
  • I added Korean from mysql server itself. So I can see it from mysql server that Korean exists. When I run the php file to display all the elements from the mysql database, SELECT * FROM TableName, the Korean is returned as that ud638\ud638\ud638\ud558\ud558\ud558\ud558 – coolcool1994 Aug 13 '13 at 10:11
  • Adding your 1) 2) to my php file did not solve this problem of returning korean. I am calling my php file from the web, because that is the first, the best way to test. and korean is not returned – coolcool1994 Aug 13 '13 at 10:12