简体   繁体   English

MySQL查询建议/帮助

[英]Mysql query advice/help needed

I am building a site where candidates can post their resume and employers can post their jobs. 我正在建立一个网站,候选人可以在其中发布简历,而雇主可以在其中发布职位。

The employers can post a job with multiple qualifications and I saved it in database like this PHP,Javascript,ASP . 雇主可以发布具有多种资格的工作,我将其保存在PHP,Javascript,ASP这样的数据库中。 Now I want admin to be able to select the candidates who are eligible for a post. 现在,我希望管理员能够选择符合职位资格的候选人。

I have written the query: 我写了查询:

$sql = "
        SELECT
            cand_f_name,
            cand_l_name,
            cand_qualification,
            cand_phone,
            cand_email,
            cand_experience_yr,
            cand_experience_mn,
            cand_message,
            cand_id
        FROM
            tbl_cand_data
        WHERE
            cand_qualification LIKE '%$emp_q%' 

But it is not showing the expected result. 但这并没有显示出预期的结果。 I think my condition cand_qualification LIKE '$emp_q' is wrong. 我认为我的条件cand_qualification LIKE '$emp_q'是错误的。

My tbl_cand_data : 我的tbl_cand_data: 在此处输入图片说明

If you are doing a LIKE query you should include wildcards, as they will match a string containing, otherwise just do an exact match using =: 如果要进行LIKE查询,则应包含通配符,因为它们将匹配包含的字符串,否则只需使用=进行完全匹配即可:

// String match
WHERE
    cand_qualification LIKE '%emp_q%';

// Exact match
WHERE
    cand_qualification = '$emp_q';

// You could try a WHERE IN clause as well
WHERE cand_qualification IN ('$emp_q');

// Values have to be quoted individually
WHERE cand_qualification IN ('BA','BSc','BCom');

// If you have an array you can do this:    
$myArray = array('BA', 'BSc', 'BCom');
$emp_q = "'" . implode("','", $myArray) . "'"; //Output 'BA', 'BSc', 'BCom'

I saved it in database like this PHP,Javascript,ASP 我将其保存在这样的PHP,Javascript,ASP等数据库中

That's what you did utterly wrong. 那就是你完全错误的做法。

you have to create a related table (that's why our ratabase called relational one!) storing qualifications, and interconnection table, consists of qualifications id linked with candidates ids. 您必须创建一个相关的表(这就是为什么我们的ratabase称为关系表!)来存储资格和互连表,该表由与候选人ID链接的资格ID组成。
And query them using basic joins. 并使用基本联接查询它们。

Note that despite of your current decision, even if you decide to continue with your lame schema, you WILL have to remake it proper way, sooner or later (but sooner will make you less work). 请注意,尽管做出了当前的决定,即使您决定继续使用la脚的架构,您也将迟早必须以适当的方式重新构建它(但越早会使您的工作量越少)。
That is the very basics of database architecture and noone can go against it. 那是数据库体系结构的最基础知识,没有人可以反对它。

SELECT fields FROM tbl_cand_data d, qualification q, qual_cand qc 
WHERE q.name = 'ASP' AND q.id=qc.qid AND d.id=qc.did

喜欢,需要%%尝试一下

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

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