I have an sql query which returns values. I would want to add new values with keys so that I can use it to my next controller which is these values doesn't come from the query result.
My Model:
$paymentDetails = $this->db->query($sql);
$payments = $paymentDetails->result();
//these are the values I wanted to add to the result for the $payments
$amountDue = 'Sample';
$change = 'Sample';
$result = array_merge($payments, array(
"AmountDue" => $amountDue,
"Change" => $change
));
if($result){
return $result;
}else{
return false;
}
I wonder why array_merge() doesn't work. In my view, values fetched from the SQL Query did returned, but the added (AmountDue and Change) is not found.
Please help me. Thank you so much! Ya'll be a big help for my project. :)
because result() function returns the query result as an array of objects, or an empty array on failure. It is just an alias of result_object().
You have to use result_array() which returns the query result as a pure array.
I hope this will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.