1
I have a php code that picked up information from two different columns of the same table in a local database, but the code doesn’t seem to work when one of the columns has information with space, for example: "Romeo Juliet" but if it is written: "Romeo Juliet" the code works, can anyone help me? Follows the code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "teste";
$conn = new mysqli ($servername,$username,$password,$dbname);
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$sql1 = "SELECT abbreviation,image FROM je";
$result1 = $conn->query($sql1);
$i=0;
$resultado = array(array(),array());
while ($row = $result1->fetch_assoc()){
$resultado[$i]["imagem"] = $row["image"];
$resultado[$i]["abrevia"] = $row["abbreviation"];
$i++;
}
echo json_encode($resultado);
?>
I believe your problem is with accents or special characters, try this way: json_encode( $result, JSON_UNESCAPED_UNICODE );
– Euler01
Could you display the result to check? In principle, it is not to happen what was described in the code shown. The error could be in the data, or in their verification. Taking advantage, in this line it is worth mentioning that you are creating an array with 2 empty arrays that will not help you at all:
$resultado = array(array(),array());
(if you give aprint_r
in the generated array, you may understand better)– Bacco