我使用Codeigniter来使用一些查询,到目前为止这是我的代码。我的代码是否正确?
$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");
以及如何使用此变量更改数字
$this->session->userdata('ID')
答案 0 :(得分:0)
试试这个
$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 :(得分:0)
您可以使用下面的Query Bindings自动转义它:
$sql = "(SELECT SUM(grand_total) FROM Sales_order WHERE member = '?') - (SELECT SUM(amount) FROM payment WHERE member_id = '?') AS total_sales";
$this->db->query($sql, array($this->session->userdata('ID'),$this->session->userdata('ID')));