Question

I have a function in the controller that gets a string and then queries the database (via the model) for records that have this string as their name. This works fine with English but I have a problem when the input is in Hebrew. When I echo the string I see something like %D7%91 and the query fails. All database tables entries are defined as utf8_general_ci.

My controller code:

function get_records_by_name($name)
{
            echo 'searching for: '.$name.'</br>';
    $keys = new DMkeys() ; 

    $query = $keys->get_keys();

    $arr = array();

    $count = 0;

    foreach ($query->result() as $row) 
    {
        if(stristr($row->name, $name) != FALSE)
        {
            $arr[] = $row->name;
            $count++;
            echo $row->name.'</br>';
        }
    }

    $result = array('count' => $count, 'list' => $arr);

    echo json_encode($result) ;  
}

My model code:

function get_keys()
{
    $query = $this->db->get('keys');
    return $query;
}

Thanks, Simon

Était-ce utile?

La solution

You need to decode the variable before using it, try:

$name = urldecode($name);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top