I am trying to return an array called from a public function stored in a PHP file. The returned array I need to export is in JSON format. I have the below code for calling the array (which in other cases works), but the output is just Array (the sql in phpMyAdmin returns all data)
This is the public function that should return the array, stored in a general PHP class file.
public function getIssueList() {
$sql = "select * from IssueData";
$returnValue = array();
$result = $this->conn->query($sql); // makes the connection and executes the sql
if ($result != null) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
}
Then I call the public function from below code:
$result = $dao->getIssueList(); //opens the connection and calls the public function
echo $result;
But the echo result I get is just the word "Array"
Above code works for other public functions, but it returns only one row and not multiple as I need in this case. Also I need to get the array as associative.
What might be wrong?
$returnValue = $row;to$returnValue[] = $row;andecho $result;toprint_r($result);.->fecth_array()-> Fetch a result row..., so if you want mulitiple rows you need to do a loop, and add each row to an array. (2) sincereturn $returnValue;will return an array, you can't justecho $result;. You could useprint_r($result);orvar_dump($result)or ...