A confirm about a SQL query - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: A confirm about a SQL query (/showthread.php?tid=67494) |
A confirm about a SQL query - gbwebapps - 02-28-2017 Hi there. I have a sql query perfectly working, however I'd like to know if it could be write in a better way or in a more efficient way. I have this scenario: in a database I have 4 tables, brands, categories, products and another table called categories_to_product which is a lookup table composed by two field, product_id and category_id, which let have to products, more than one category. brands ------------- id brand categories ------------- id category products ------------- id brand_id (fk of brands) categories_to_product ------------- product_id category_id In the products visualization, I have three fields for an advanced search (pic_01) The problem I've tryied to solve for some days, it was the category field. At final I solved with this code: Code: if(isset($_POST['for_product'])): Someone can be give me an opinion about this sql code? Thank you and sorry for my prolixity... G RE: A confirm about a SQL query - Wouter60 - 03-01-2017 The Query Builder options in CI offer a good method to create sub-queries: PHP Code: if ($for_category) { RE: A confirm about a SQL query - gbwebapps - 03-01-2017 Thank you a lot for your reply! I will test it right now! G |