I have this php code :
public function getcabang(){
$cabang = $this->conn->prepare("SELECT nama_cabang,alamat FROM cabang");
if ($cabang->execute()){
$cbg = $cabang->get_result()->fetch_assoc();
$cabang->close();
return $cbg;
} else {
return NULL;
}
}
but it always returning 1 row :
{"error":false,"cabang":{"nama_cabang":"Senayan","alamat":"Pintu 1 Senayan"}}
even though it have more than 1 row in table
You need to iterate to get every row, here is an example from php.net :
In your case, that would be :
Also, a better solution could be to use mysqli_fetch_all (Available only with mysqlnd)