douguluan5102 2015-01-14 09:30
浏览 42
已采纳

合并$ query-> result()和数组codeigniter的结果

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. :)

  • 写回答

1条回答 默认 最新

  • dqrfdl5708 2015-01-14 12:26
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化