简体   繁体   English

比较PHP中的MySQL数据库表值

[英]comparing mysql database table values in php

I've added database structure at the bottom 我在底部添加了数据库结构

I have a ranking system in the making for a recruitment agency.. I capture all applicants details in different tables, and to rank them (if they fit the needs/requirements of a certain job advert) by comparing the data of the candidates that is in the database to the job in the job_advert table. 我正在为招聘机构制定排名系统。我在不同的表格中捕获所有申请人的详细信息,然后通过比较候选人的数据对他们进行排名(如果它们符合特定职业广告的需求/要求)。数据库中的作业到job_advert表中的作业。 And then display a list of the 10 best ranking (qualified) candidates would be sent a notification that they qualify for the job. 然后显示10个最佳排名(合格)候选人的列表,并向他们发送通知,告知他们符合该职位的条件。

I get the candidates data from the database like so: 我从数据库中获取候选人数据,如下所示:

class ranking_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function age() {
        $sql = "SELECT * FROM membership";
        $query = $this->db->query($sql)->result();
        foreach ($query as $row) {
            $id = $row->id_number;
            $dobs = substr($id, 0, 6);
            $dob = str_split($dobs, 2);
            $day = date('d', mktime(0, 0, 0, 0, $dob[2], 0));
            $month = date('m', mktime(0, 0, 0, $dob[1] + 1, 0, 0));
            $year = date('o', mktime(0, 0, 0, 0, 0, $dob[0] + 1));
            $date = "$day/$month/$year";
            //explode the date to get month, day and year
            $date = explode("/", $date);
            //get age from date or birthdate
            $age = (date("md", date("U", mktime(0, 0, 0, $date[0], $date[1], $date[2]))) > date("md") ? ((date("Y") - $date[2]) - 1) : (date("Y") - $date[2]));
        }
        return $age;
    }

    function job_experience() {
        $sql = "SELECT * FROM  job_list 
        JOIN job_history
        ON job_list.job_history_id = job_history.job_history_id";
        $query = $this->db->query($sql)->result();

        foreach ($query as $row) {
            $start = $row->start_date;
            $end = $row->end_date;

//            //explode the date to get month, day and year
            $start = explode("-", $start);
            $end = explode("-", $end);
//            //get age from date or birthdate
            $exp_in_years = (date("md", date("U", mktime(0, 0, 0, $start[2], $start[1], $start[0]))) > date("md", mktime(0, 0, 0, $end[2], $end[1], 0)) ? ((date("Y", mktime(0, 0, 0, 0, 0, $end[0])) - $start[0])) : (date("Y", mktime(0, 0, 0, 0, 0, $end[0])) - $start[0]));
        }

        return $exp_in_years;


    }

    function location() {
        $sql = "SELECT * FROM personal";
        $query = $this->db->query($sql)->result();

        foreach ($query as $row) {
            $city = $row->city;
        }
        return $city;
    }

    function relocate() {
        $sql = "SELECT * FROM personal";
        $query = $this->db->query($sql)->result();

        foreach ($query as $row) {
            $relocate = $row->relocate; //are you willing to relocate yes/no
        }
        return $relocate;
    }

    function get_personal() {
        $this->db->select('*');
        $this->db->from('membership');
        $this->db->join('personal', 'membership.id_number = personal.id_number');
        $query = $this->db->get()->result();

        foreach ($query as $row) {
            $row->id_number;
            $row->firstname;
        }
        return $query;
    }

and the advert details like this: 以及类似这样的广告详细信息:

    function get_advert() {
        $sql = "SELECT * FROM job_advert";
        $query = $this->db->query($sql)->result();
        foreach ($query as $row) {

            $job_id = $row->job_id;
            $job_title = $row->job_title;
            $salary_offered = $row->salary_offered;
            $is_negotiable = $row->negotiable;
            $company_location = $row->company_location;
            $experience = $row->required_experience;
            $age = $row->age;
        }
    }

}

now I don't know how to compare the candidates data with the data that I get from the job_adverts table. 现在,我不知道如何将候选数据与从job_adverts表获得的数据进行比较。 I really have no idea. 我真的不知道。 Help of any sort would be appreciated. 任何形式的帮助将不胜感激。

Database structure 数据库结构

bold PK itacic is FK . 大胆的PK itacic是FK

membership( id_number , firstname, lastname, username, email, phone, password, role, Reg_time, activated); 成员资格( id_number ,名字,姓氏,用户名,电子邮件,电话,密码,角色,Reg_time,已激活);

personal( person_id , address, city, licence, id_number , gender, relocate, minimum_salary, prefered_salary, contract_type); 个人( person_id ,地址,城市,许可证, id_number ,性别,搬迁,minimum_salary, id_number ,contract_type);

job_list( job_list_id , job_history_id , start_date, end_date, income, company_name, industry_type, reason_for_leaving, job_title); job_list( job_list_idjob_history_id ,start_date,end_date,收入,company_name,industry_type,reason_for_leaving,job_title);

job_history( job_history_id , id_number ); job_history( job_history_idid_number );

job_advert( advert_id , job_title, job_description, start_date, end_date, salary_offered, negotiable, benefits, company_location, required_experience, age); job_advert( advert_id ,job_title,job_description,start_date,end_date,提供的薪金,可协商,福利,公司位置,required_experience,年龄);

I have more tables in the db, but these are the ones I use for ranking. 我在数据库中有更多表,但是这些是我用于排名的表。

I'm not sure how much data you are working with but pulling down everything from you db and storing it in a local php variable seems like a bad idea. 我不确定您正在处理多少数据,但是从数据库中提取所有数据并将其存储在本地php变量中似乎是个坏主意。

Your db structure all seems really bad....store as much data into the members table as possible...no need to split it off into a bunch of tables unless that table is getting a large amount of columns or a its a field that a person can have multiple data points for. 您的数据库结构似乎都非常糟糕。...将尽可能多的数据存储到成员表中...无需将其拆分为一堆表,除非该表获取大量列或它的字段一个人可以拥有多个数据点。 An example of this would be prior employers...how I would approach this is create a link/join table called membersData with a membersDataType = 'employeer' 一个例子是以前的雇主...我将如何处理这个问题,就是创建一个名为membersData的链接/联接表,并使用membersDataType ='employeer'

If I was to approach this problem I would do the following... 如果要解决此问题,请执行以下操作...

1) create an html form that displays all the job postings. 1)创建一个HTML表单,显示所有职位发布。 When you choose one of the jobs from the dropdown it submits the form and the job_id. 当您从下拉列表中选择作业之一时,它将提交表格和job_id。

2) select the job data from the db for that job_id 2)从数据库中为该job_id选择作业数据

3) build a query that matches each criteria 3)建立符合每个条件的查询

$query = "SELECT * FROM members WHERE";
if ($job["age"]){ $query .= " age > ".$job["age"]; }

Although you have not posted the database structure, you can try to create a relationship between the tables. 尽管尚未发布数据库结构,但是您可以尝试在表之间创建关系。 You can associate aa set a candidates with some records from job_advets. 您可以将一个求职者与job_advets中的某些记录相关联。 In the recruitment process some candidates depending on experience will become compatible or not with certain positions in the company. 在招聘过程中,一些根据经验而定的候选人将与公司中的某些职位兼容或不兼容。 So job_experience function for each candidate will have to determine whether a particular job for which he applied it is compatible or not. 因此,每个候选人的job_experience函数必须确定他所应用的特定工作是否兼容。

That's gonna be interesting :) 那会很有趣的:)

I guess the easiest is $exp_in_years > $experience and ($salary_offered >= $salary_asked_for) OR $is_negotiable - but even there you probably need to include a few % below these limites ($exp_in_years * 0.9) > $experience . 我猜最简单的是$exp_in_years > $experience($salary_offered >= $salary_asked_for) OR $is_negotiable但即使在那儿,您可能还需要在这些限制以下($exp_in_years * 0.9) > $experience包括几个百分点。

$job_title : will probably require a VERY good naming-scheme and some very tolerant checking $job_title :可能需要非常好的命名方案和一些非常宽容的检查

$company_location : I'd suggest to use web-service which will calculate the distance between compan's location and applicants location - but I haven't done that yet, so can't help with details, sry. $company_location :我建议使用网络服务,该服务将计算公司的位置与申请人的位置之间的距离-但是我还没有这样做,所以无法提供详细信息,抱歉。

yet...despite all automation...you probably still need humans to filter, so I'd rather give them a larger set of candidates than eliminate totally appropriate candidates just because of one "little" test that failed somewhere... 但是...尽管有所有自动化...您可能仍然需要人工进行筛选,所以我宁愿给他们提供更多的候选人,而不是仅仅因为一个“小”测试在某处失败而淘汰完全合适的候选人...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM