First off, let me apologise for the title, I couldn't get the wording correct. Anyway, here's my problem, I have a table with user's qualifications like so:
Qualifications table
CREATE TABLE IF NOT EXISTS `qualifications` (
`qualification_id` int(11) NOT NULL,
`qualification_qualification` varchar(255) NOT NULL,
`qualification_establishment` varchar(255) NOT NULL,
`qualification_dateobtained` date NOT NULL,
`qualification_about` varchar(255) NOT NULL,
`qualification_user` int(255) NOT NULL,
`qualification_date` datetime NOT NULL,
`qualification_enabled` int(11) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Now when another use adds a job, they can add required qualifications before said user can apply, which puts it in the tables jobs like 1,2,3 which is the qualification_id
Now in my SQL I want to check multiple qualification_id to see if they're IN the job_requirements Here is my job table:
jobs table
CREATE TABLE IF NOT EXISTS `jobs` (
`job_id` int(11) NOT NULL,
`job_name` varchar(100) NOT NULL,
`job_description` text NOT NULL,
`job_duration` int(11) NOT NULL,
`job_country` varchar(100) NOT NULL,
`job_category` int(50) NOT NULL,
`job_user` int(100) NOT NULL,
`job_employer` varchar(100) NOT NULL,
`job_enabled` int(2) NOT NULL DEFAULT '1',
`job_startdate` date NOT NULL,
`job_wage_type` int(1) NOT NULL,
`job_wage` int(9) NOT NULL,
`job_requirements` varchar(255) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
At the moment, this is the way I am doing it, I am using a foreach for all of the user's qualifications, then using IN which isn't working because I have done it wrong, here is my PHP code:
//get job details so we can get the requirements
$job = $database->prepare("SELECT * FROM jobs WHERE job_id = ?");
$job->execute(array($id));
$job_results = $job->fetch();
//get the users qualifications
$user_qualifications = $database->prepare("SELECT * FROM qualifications WHERE qualification_user");
$user_qualifications->execute(array($user->user_id));
$user_results = $user_qualifications->fetchAll();
//I need to do this in 1 query FFS.... use IN(1,2,3,4)
//check if qualifications meet requirements
foreach ($user_results as $requirements):
//check if id is IN job requirements
$requirement_check = $database->prepare("SELECT * FROM jobs WHERE qualification_qualification IN(jobs_requirements)");
endforeach;
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire