I was trying to get the response from an SQL select statement but when I try to echo the array encoded to JSON I don't have anything written except the "-" I echo to ensure myself that is entering into the loop.
$sql = "SELECT * FROM PREGUNTA WHERE PREGUNTA.pregunta LIKE '%$palabra_clave%' OR PREGUNTA.respuesta_correcta LIKE '%$palabra_clave%' OR PREGUNTA.respuesta_falsa_1 LIKE '%$palabra_clave%' OR PREGUNTA.respuesta_falsa_2 LIKE '%$palabra_clave%' OR PREGUNTA.retroalimentacion LIKE '%$palabra_clave%'";
$query = mysqli_query($con, $sql);
$json = array();
while($data = $query->fetch_assoc()){
$json[] = array(
'pregunta' => $data['pregunta'],
'respuesta_correcta' => $data['respuesta_correcta'],
'respuesta_falsa_1' => $data['respuesta_falsa_1'],
'respuesta_falsa_2' => $data['respuesta_falsa_2'],
'retroalimentacion' => $data['retroalimentacion']
);
echo $data['pregunta'];
echo '<br>';
}
echo json_encode($json);
And I this is my output:
¿Cuál no es un lenguaje de programación web?
¿Cuál es el lenguaje web más importante?