/ Published in: SQL
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
FUNCTION findunUsedCats($aid){ $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);"; $query = mysql_query($query)OR die("nope..".mysql_error()); RETURN $query; }