Hi @Dormilich and @StarLion. Thank you bot for the reply. I think I didn’t explain myself right.
This is the method to get the right category_options:
public function get_product_options($catId,$subCatId)
{
$sql = "SELECT *
FROM category_options
WHERE category_id = ?
AND sub_category_id = ?";
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array($catId,$subCatId));
return $stmt->fetchAll();
}
This are the values in category_options:
INSERT INTO `category_options` (`option_id`, `category_id`, `sub_category_id`, `option_name`, `option_price`) VALUES
(1, 1, NULL, 'Digitaal bestand Hi-Res', '25.00'),
(2, 1, NULL, 'Afdruk canvas 30x40', '59.95'),
(3, 1, NULL, 'Afdruk canvas 50x70', '89.95'),
(4, 1, NULL, 'Afdruk canvas 70x100', '169.95'),
(5, 2, NULL, 'Digitaal bestand Hi-Res', '25.00'),
(6, 2, NULL, 'Afdruk 10x15', '2.50'),
(7, 2, NULL, 'Afdruk 15x20', '5.00'),
(8, 2, NULL, 'Afdruk 20x30', '10.00'),
(9, 2, NULL, 'Afdruk 30x40', '20.00'),
(10, 2, NULL, 'Afdruk canvas 30x40', '49.95'),
(11, 2, NULL, 'Afdruk canvas 50x70', '89.95'),
(12, 3, 6, 'Frame 20 x 30', '13.95'),
(13, 3, 6, 'Frame 30 x 40', '18.95'),
(14, 3, 6, 'Frame 40 x 50', '24.95'),
(15, 3, 7, 'Frame 20 x 30', '11.95'),
(16, 3, 7, 'Frame 30 x 30', '14.95'),
(17, 3, 7, 'Frame 30 x 40', '16.95'),
(18, 3, 7, 'Frame 40 x 50', '23.95'),
(19, 3, 8, 'Frame 20 x 30', '12.95'),
(20, 3, 8, 'Frame 30 x 30', '14.95'),
(21, 3, 8, 'Frame 30 x 40', '19.95'),
(22, 3, 8, 'Frame 40 x 50', '25.95'),
(23, 4, 9, 'Slip in 100', '4.95'),
(24, 4, 9, 'Slip in 200', '14.95'),
(25, 4, 10, '', '24.95'),
(26, 4, 11, '', '24.95'),
(27, 4, 12, '1000 stuks', '3.95'),
(28, 4, 12, '3 x 1000 stuks', '10.00');
The first 2 category_id’s dont have a sub_category_id as you can see. The last 2 do have a sub_category_id. I just would like to use the same query for both options. This is what I have in the controller now:
$product_details = $this->shop->get_product_photo_details($photoId);
$catId = $product_details['category_id'];
$subCatId = $product_details['sub_category_id'];
$product_options = $this->shop->get_product_options($catId,$subCatId);
As I said. category_options with category_id’s 3 and 4 are returning the right values, the first two on t6he other hand that have NULL as value for sub_category_id, are not returning values.
Does this makes any sense?