duanjiu3486 2017-06-21 17:31
浏览 41
已采纳

在Get_Where查询中匹配JSON字段(代码点火器)

I am doing a result_array() in my get_where query but the column in 'added_by' is json format to {'id': '(the id)'}

How Can I do a get_where query to match the current users id.

Heres what I have so far.

$this->db
     ->order_by('till', 'desc')
     ->get_where('coupon', 
          [
               'added_by' => json_encode(array('id'=> $this->session->user_id)), 
               'status' => 'ok'
          ]
     )
     ->result_array()
  • 写回答

1条回答 默认 最新

  • doru52911 2017-06-21 17:52
    关注

    json_encode will return {"id": $id}. If you are OK with {"id": "$id"}, then you just need to force coerce to string:

    json_encode(array('id'=> $this->session->user_id . ''))
    

    If you need {'id': '$id'}, you will need to do a string replace manually.

    str_replace( '"', '\'', json_encode(array('id'=> $this->session->user_id . ''))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line