I have three tables such as user, job and job_applied. user table has uid , job table has jid and job_applied has uid and jid . I need to get job title, description, position of job table according to uid and jid of job_applied table.
I’m able to get values from below code, But i think this is the wrong way (crude way) .
$this->jobapplieds = $this->getUser()->getUser()->getJobApplieds();
foreach($jobapplieds as $ja)
{
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(JobPeer::TITLE);
$c->addSelectColumn(JobPeer::DESCRIPTION);
$c->addSelectColumn(JobPeer::STATUS);
$c->add(JobPeer::JID,$ja->getJid());
$rs = JobPeer::doSelectRS($c);
while($rs->next())
{
echo $rs->getString(1);
print $rs->getString(2);
}
echo $ja->getAppliedAt();
}
If the current user has applied for 10 jobs, you currently do 10 + 1 queries (one to get all applications and then one per job). You can improve this in two ways:
Instead of doing 10 queries in your loop, you can first collect all
jidvalues in an array and then do anINquery, so you do 1 + 1 queries.The other option is to do one query where you start with the
jobtable, join it with thejob_appliedtable, and set theuidof thejob_appliedtable to your current user ID. This should execute only one query.