[SOLVED] problem with query+php+json

Issue

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

Solution

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.

Answered By – ntdt

Answer Checked By – Senaida (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *