0

i have this code to search in the bd for values identically to design

<?php
include("includes/banco.php");
$theclass->conecta();

$more= "design";  

$rs = mysql_query('select abcd from house where abcd like "'.$more .'%"');

$data = array();
if ( $rs && mysql_num_rows($rs) )
{
    while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
    {
        $data[] = array(
            'label' => $row['abcd']  
        );
    }
}

echo json_encode($data);
flush();

?>

In the bd i have design in the first id and design gráfico in the second id

the result is this:

[{"label":"Design"},{"label":null}]

if i change the bd to design grafico the result is

[{"label":"Design"},{"label":"Design grafico"}]  

so, it has some problem with the codification or what?

thanks

3
  • I'm sorry, but your question is completely unclear.
    – Matt Ball
    Apr 13, 2011 at 18:34
  • Eesh.. If $more is actually going to be populated with user input, $_GET or $_POST data (or anything else external), I hope you're planning on properly sanitizing it. Apr 13, 2011 at 18:34
  • it is the next step, but now the problem is other, thanks
    – daniel__
    Apr 13, 2011 at 18:37

1 Answer 1

0

Did your database encoding is UTF-8 or ISO-8859-1 ? If it is UTF-8, try

mysql_query("SET NAMES UTF8"); 

after connect to mysql.

1
  • If your DBMS MySQL is configured by default to UTF-8 then "SET NAMES UTF-8" is not necessary.
    – ntdt
    Apr 15, 2011 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.