dqef7931
2017-06-06 04:32
浏览 45
已采纳

在SQL查询Codeigniter中插入PHP变量

I'm using Codeigniter to use some queries and this is my code so far. is my code correct?

$this->db->select("(SELECT SUM(grand_total) FROM Sales_order WHERE member = '2') - (SELECT SUM(amount) FROM payment WHERE member_id = '2')  AS total_sales");

and how to change number 2 with this variable
$this->session->userdata('ID')

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dqs13465424392 2017-06-06 04:33
    最佳回答

    Try this

    $this->db->select("(SELECT SUM(grand_total) FROM Sales_order WHERE member = '".$this->session->userdata('ID')."') - (SELECT SUM(amount) FROM payment WHERE member_id = '".$this->session->userdata('ID')."')  AS total_sales"');
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题