Need help for complex query |
I have a product table, category table and another table to join product and category where category stored in JSON format. What I need to do is to get all the product with a list category IDs.
Category table Code: ----------------------- Product table Code: ----------------------- Product Category relation table Code: ----------------------- According to example, what will be the query if I need to get all the product with the category list (array)[34,18,6] I will be very glad if you suggest any better table structures. Thanks in advance. ![]()
PHP Code: //With current data store: Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
After
PHP Code: $query = "SELECT * FROM Product WHERE id IN (".$sql.")"; Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
It is not very nice way to store multiple values in one field - it is not convenient and not practical.
You can modify your relationship table to store category IDs one per field, but on different rows. So your table structure should be: Category table: Code: ----------------------- Product table: Code: ----------------------- Product_category table: Code: ----------------------- |
Welcome Guest, Not a member yet? Register Sign In |