我正在尝试通过代码在Codeigniter中结合Where和OR。
$this->db->where("id",1);
$this->db->where("status","live")->or_where("status","dead");
出现的结果是as查询
where id=1 and status='live' OR status='dead'
而我需要这个查询的结果。
where id=1 and (status='live'
我是CI的新手。实际上,我想从我的product表中获取数据。具有多个where条件,即具有指定的menu_ids,但是所有的限制都应该是1,这意味着我希望每个menu_id中有一个产品。下面是我的模型,可能是错误的。请帮帮忙。
My Model
public function home_products(){
$this->db->select('*');
$this->db->from('product');
$this->db->where
如何使用代码点火器活动记录编写where_in语句(子查询)?
$query = $this->db->query("SELECT SUM(a.transaction_payment_amount) FROM
transaction_payment a WHERE a.transaction_link IN
(SELECT transaction_link FROM transaction WHERE transaction_type = '22'");
$result = $query->result(
我在Codeigniter中有一些代码,看起来像这样:
$this->db->select('email_account_id');
$this->db->where('TRIM(LOWER(email_account_incoming_username))',trim(strtolower($email_address)));
$query = $this->db->get($this->users_db.'email_account');
抛出此错误:
You have an error in you
我正在使用codeigniters sql选择来选择不在一组id中的用户。
$this->db->select('fbuid')->where_in('fbuid', $friends);
$query = $this->db->get('users');
我正在尝试添加另一个子句,它检查而不是在朋友表(id列)中。我试着增加使用
$this->db-where_not_in
但我似乎不能让它起作用
下面是一个伪代码sql语句
SELECT fbuid FROM users WHERE IN () BUT
我正在尝试让codeigniter中的where()和or_where()与介于两者之间的AND一起工作。我希望我的查询看起来像下面这样。
SELECT fname
FROM users
WHERE is_active = 1 AND (
employee_type = 'graduate' OR employee_type = 'staff' OR employee_type = 'Person Of Interest'
)
下面是我当前的代码:
$this->db->select($print_data);
$this
下面我的mysql查询有个奇怪的问题。如果我错了,请纠正我。
下面的查询(我从Codeigniter打印)给出了subject = 4的结果。
WHERE `notes`.`subject` IN ('4,2') GROUP BY `notes`.`id` ORDER BY `created_date` DESC
但当我改变了这个
WHERE `notes`.`subject` IN ('2,4') GROUP BY `notes`.`id` ORDER BY `created_date` DESC
它不会返回任何结果。为什么会这样呢?让我说,我只有一个
我正在使用codeigniter查询数据库,并且我需要有条件地比较where子句中的数组。
所以基本上我想做的是: where_in还是where_in,这取决于其中包含数据的数组。因此,我将拥有一个区域数组或一个user_id _id数组。
我不确定如何结合where_in比较。这是我需要修正的查询:
public function get_checks_test($org_id,$users,$areas) {
// get todays date
$todays_date = date("Y-m-d");
// build where array
我遇到了一个动态返回多行的问题。
我有一个活动记录查询,需要从同一个表中返回多个行。
//this will be a dynamic array of ids
$array = array('01','02','03');
//i need to have other where conditionals as well
$cond['userlevel'] = 5;
//then add the array of ids to the conditionals array
$cond['id
Controller:
public function search_products_auto(){
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('homemodel','',TRUE);
我的CodeIgniter中有一个下面的查询,我试图通过参数绑定它。
$q = "SELECT * FROM my_table WHERE id IN (?)"
$ids = "1,2,3,4";
$this->db->query($q, array($ids));
上面的方法不起作用,因为查询绑定将$ids视为字符串。我如何参数化我的查询,同时仍然能够执行"IN“操作?
编辑
对不起,我必须使用“原始SQL查询”。上面的查询只是一个更大的+复杂查询的一部分,我不能使用ActiveRecord。另外,我正在使用Postgres。
我有一个包含以下数据的用户表: id first_name
10 user one
21 user two
39 user 3 因此,我希望获取具有特定id的所有用户,例如,当我传递id为10和21时,我希望检索前2个用户。 在Codeigniter中,我的模型中有一个函数getUsersByIds,如下所示: class UsersModel extends CI_Model{
public function getUsersByIds($ids){
$data = [];
foreach($ids as it