I'm trying to write up an email notification system for a job recruitment site I made and am currently looking at grouping a certain amount of jobs together before sending an email to the candidate
I have a table which I've called candidate_to_job which contains the candidate_id, job_id and an "emailed" boolean
What I'm struggling with is updating that table when a new job is posted and emails are sent out. So far when a new job is posted I run the following:
SELECT c2j.candidate_id, c2j.job_id, j.title
FROM " . DB_PREFIX . "candidate_to_job c2j
LEFT JOIN " . DB_PREFIX . "job j
ON (j.job_id = c2j.job_id)
WHERE c2j.emailed = 0
Then through PHP I group them all together so I have an array looking something like this:
$candidates = array(
1 => array(1,2,3),
2 => array(1,3),
3 => array(4,5,6)
);
With the array key being the candidate ID and the value an array of job IDs
What I want to do using that array - after the emails have been sent - is update the candidate_to_job table setting emailed to true, e.g candidate_id 1 would have emailed set to true for job_ids 1, 2 and 3
Is there a way I can do this in one query? I've looked at WHEN CASE statements but I don't think that applies in this case? I really don't want to run multiple queries per candidate because there could potentially be thousands!