I have been racking my brain looking for an answer to this very simple question.
I have two tables with data in them. The first table contains a group of categories and their id. The second table contains a group of posts that can be linked to each category. Now I need to select the posts that are in each category, but it's not working the way I expect. I have tried using the IN operator and it works on the first value in the rows then doesn't on the rest.
Here is how the tables are roughly structured
Category Row Structure:
+===================+
| cID | cName |
+===================+
| 1 | cars |
| 2 | trucks |
| 3 | kittens |
| 4 | quads |
+===================+
Post Structure:
+==========================================+
| pID | title | content | cats |
+==========================================+
| 1 | a post 1 | text here | 1,3,4 |
| 2 | a post 2 | text here | 2,3,4 |
| 3 | a post 3 | text here | 1,4 |
| 4 | something | text here | 2 |
+==========================================+
When I visit the page for the cars
category, it runs a query similar to this
$showFrom = 1; // THE cID of the Cars category
query_function("SELECT .. FROM entries WHERE cats IN (?)", array($showFrom));
// Query function just prepares the statement and passes the variables to the function
With this function I see a post 1
and a post 3
show up. Great. But if I go to the kittens or quads page, I am not seeing these posts. It stops reading after 1 in the first and 3rd item, and 2 on the second and fourth item.
I considered using the CONTAINS function, but if they have more then 9 categories, and you visit category 1, you would see category 10 and 11 and so on as they would CONTAIN the literal value of 1 right? Or am I missing something here?
Thanks