簡體   English   中英

合並$ query-> result()和數組codeigniter的結果

[英]Merging result from $query->result() and an array codeigniter

我有一個返回值的SQL查詢。 我想用鍵添加新值,以便可以將其用於下一個控制器,因為這些值不是來自查詢結果。

我的模特:

$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;
}

我不知道為什么array_merge()不起作用。 在我看來,確實返回了從SQL查詢中獲取的值,但是找不到添加的(AmountDue和Change)。

請幫我。 非常感謝! 對我的項目有很大的幫助。 :)

因為result()函數以對象數組或失敗時為空數組的形式返回查詢結果。 它只是result_object()的別名。

您必須使用result_array()將查詢結果作為純數組返回。

我希望這能幫到您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM