开发者

Help with MySQL query clause in CodeIgniter

开发者 https://www.devze.com 2022-12-20 09:38 出处:网络
I need some help solving a problem with mySQL, is it possible to pass an array to a function and then run a match agains the array values?

I need some help solving a problem with mySQL, is it possible to pass an array to a function and then run a match agains the array values?

I have this query

function getMenu($cookieId) {
    $this->db->select('*');
    $this->db->from('categoryTable');
    $this->db->join('userMenuTable', 'categoryTable.categoryId = userMenuTable.categoryId', 'left');
    $this->db->where('userMenuTable.cookieId', $cookieId);

    $query = $this->db->get();
    return $query->result_array();

}

Using the $query array that is returned is possi开发者_运维问答ble to query the database and get all the values from a table that do not match the array values?


Use this condition in your query:

$this->db->where_not_in('fieldname', $array_of_values);

You won't be able to directly use the array returned in your example, as it comes from a SELECT * and thus it contains all fields of the table. You have to build an array with ONLY the values of the field you want to filter you next query on.


What columns do you have in that array ? Theoretically you could do a

select from `new table` where `field` NOT IN (Select `field` from `old_table`)

to do this in just one query, or pass your array the NOT IN condition

0

精彩评论

暂无评论...
验证码 换一张
取 消