I am fairly new with PDO but i have come across something which probably has an easy answer.
I have an array of category numbers to which i need to search through a mysql database to find all items with the matching category number.
I know i have connected to DB correctly as i am receiving the category array from a different query.
$category = Array ( [0] => 3259 [1] => 3617 [2] => 3257 [3] => 3258 [4] => 3450 [5] => 3452 [6] => 3478 [7] => 3479 [8] => 3480 [9] => 3448 [10] => 3449 [11] => 3451 [12] => 3456 [13] => 3454 [14] => 3455 [15] => 3459 [16] => 3460 [17] => 3458 [18] => 3453 [19] => 3461 [20] => 3462 [21] => 3457 [22] => 3463 [23] => 3447 )
now i need to go through the item database to check for matching categories. Each item can have multiple categories, each category has 4 digits. multiple categories are seperate with a =
$categoryResults = $conn->prepare('SELECT * FROM items WHERE category like :cats ORDER BY promotions,price ASC');
$categoryResults->execute(array(':cats' => '%'.$category.'%'));
$categoryNumber = $categoryResults->rowCount();
This is where i seem to have gone wrong. With the mysql request i would have built it up manually using a loop through the array to get me a long sql query :
'Select * From items WHERE category like '%3259%' OR WHERE category LIKE '%3617%'........etc
But i am sure this is one of the advantages of using PDO. Just to add to it i need the results to be unique. If item 97 is in category 3259 and category 3617 i only want to get the result once.
Thanks in advance.