Il problema è che $output è un array su cui devi iterare. Qualcosa del genere:
function getTopic($conn){
$response = array("error" => 0);
$qry = "SELECT original_title, content, time FROM topic WHERE vis = 1";
$result = $conn->prepare($qry);
$result->execute();
if($result->rowCount() > 0){
$output = $result->fetchall();
foreach ($output as $o){
$response['text'] = $o['original_title'];
$response['test'] = $o['content'];
}
return json_encode($response);
}
} Quanto sopra mantiene solo l'ultima riga. Se le vuoi tutte, fai invece così:
function getTopic($conn){
$response = array('error' => 0);
$qry = "SELECT original_title, content, time FROM topic WHERE vis = 1";
$result = $conn->prepare($qry);
$result->execute();
if($result->rowCount() > 0){
$output = $result->fetchall();
foreach ($output as $o){
$response[] = array('text' => $o['original_title'], 'test' => $o['content']);
}
return json_encode($response);
}
} Se vuoi sempre e solo una singola riga, aggiungi semplicemente un LIMIT alla tua istruzione MySQL.