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 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)