I'm running a conditional statement to return two different sets of data depending on whether certain ids are present.
$emailContent = $emailDataResource->getEmailResourceIDs($date, $country_id, $category_id);
foreach($emailContent as $content) {
$edrIds[] = $content;
}
$a = array_fill(0, count($edrIds), '?');
$b = implode(', ', $a);
$db = DB::getInstance();
// get the resources
if(count($countryId) == 1) {
$query = "
SELECT
edr.id AS data_id, r.id, r.title, r.friendly_url, edr.position
FROM
`twinkl_email_data_resource` edr
JOIN
`twinkl_resource` r ON r.id = edr.resource_id
WHERE
edr.`date` = ?
AND edr.`country_id` = ?
AND edr.`category_id` = ?
AND edr.id NOT IN ($b)";
$params = [$date, $country_id, $category_id, implode(',', $edrIds)];
$result = $db->query($query, $params);
} else if (count($countryId) > 1) {
$query = "
SELECT
edr.id AS data_id, r.id, r.title, r.friendly_url, edr.position
FROM
`twinkl_email_data_resource` edr
JOIN
`twinkl_resource` r ON r.id = edr.resource_id
WHERE edr.id IN ($b)";
$params = [implode(',', $edrIds)];
$result = $db->query($query, $params);
}
Introducing multiple placeholders before the array of ids can be generated and passed in halts the running of the page. This means I can't make all the selections necessary to pass in all the parameters (country_id and category_id) to find the ids.