0
$query = $this->db->query("SELECT * FROM default_albums da
                               INNER JOIN default_album_hc_connect d ON d.albums_id = da.album_id_da
                               INNER JOIN default_hottest_categories dhc ON dhc.id = d.hottest_categories_id
                               WHERE dhc.is_hottest = 'Yes'");

The above is my current query. I have an array called results that is being pulled in from an ajax post. How can I take that array and return rows that don't equal the values from that array?

1 Answer 1

1

What about the NOT IN condition ?

" (...)
WHERE (...)
    AND whatever NOT IN (\"" . implode('", "', $array) . "\")";
Sign up to request clarification or add additional context in comments.

4 Comments

Unknown column '37173375051af44ce29816' in 'where clause' SELECT * FROM default_albums da INNER JOIN default_album_hc_connect d ON d.albums_id = da.album_id_da INNER JOIN default_hottest_categories dhc ON dhc.id = d.hottest_categories_id WHERE dhc.is_hottest = 'Yes' AND da.album_id_da NOT IN (37173375051af44ce29816, 185421235851af446a1be2e, 70884918151af4500e28bb) - this is my error.
Thanks man, for some reason though it's still returning all of the albums and not only the ones that don't equal up.
` $results = $this->input->post('ids'); $query = $this->db->query("SELECT * FROM default_albums da INNER JOIN default_album_hc_connect d ON d.albums_id = da.album_id_da INNER JOIN default_hottest_categories dhc ON dhc.id = d.hottest_categories_id WHERE dhc.is_hottest = 'Yes' AND da.album_id_da NOT IN (\".implode(', ', $results).\")"); foreach($query->result() as $row) { echo $row->album_name; }`
I would assume you also need to take out dhc.is_hottest='Yes' from the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.