Find all categories NOT used in current item


/ Published in: SQL
Save to your folder(s)

It's easy to find the categories used on one item, but find all categories NOT used on current item?
This snippet stores a "NOT IN" query.

This is used with PHP & mySQL. The query can be written differently on other databases, but this seems to work with mySQL.


Copy this code and paste it in your HTML
  1. FUNCTION findunUsedCats($aid){
  2. $query = "SELECT cat_tbl.cid, cat_tbl.category FROM cat_tbl WHERE cat_tbl.category NOT IN (SELECT cat_tbl.category FROM cat_tbl, art_has_cat_tbl WHERE cat_tbl.cid = art_has_cat_tbl.cid AND aid =$aid);";
  3. $query = mysql_query($query)OR die("nope..".mysql_error());
  4. RETURN $query;
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.