PHP MYSQL选择多个变量

时间:2019-02-22 17:13:13

标签: php mysql select

我有一个包含用户ID(candidate_id)和技能的表

enter image description here

在一个单独的表(required_skills)上,我的一列包含用逗号(,)分隔的技能,例如Administrator,office

我正在尝试创建SELECT语句,以查找候选人具有“ required_skills”表中列出的所有技能的位置。

我尝试使用数组,但是对它们的了解不足...

$myString = "$skills";
$myArray = explode(',', $myString);
foreach($myArray as $my_Array){

$result=mysql_query("SELECT * FROM candidate_skills WHERE skill LIKE '%$my_Array%'");

这显然不能满足我的要求,因为它会为每一行创建一条选择语句...

有人可以建议吗?

2 个答案:

答案 0 :(得分:1)

在数据库中放入逗号分隔的列表几乎总是错误的处理方式。您应该有单独的表格,分别列出技能,候选人以及所需的各种技能;还有两个表格:一个将候选人与技能联系起来,另一个将技能所需的事物与他们所需的技能联系起来。然后,您可以使用这些中间表来衡量候选人技能组合对所需技能的满足程度。

这将为您提供所有具备至少一项所需技能的应聘者的列表,并按他们从最佳到最差的技能数量排序:

SELECT vs.vacancy_id, cs.candidate_id
   , COUNT(DISTINCT vs.skill_id) AS requiredSkillCount
   , COUNT(DISITCT cs.skill_id) AS candidateSkillCount
FROM vacancy_skills AS vs
LEFT JOIN candidate_skills AS cs ON vs.skill_id = cs.skill_id
WHERE vs.vacancy_id = something
GROUP BY vs.vacancy_id, cs.candidate_id
ORDER BY candidateSkillCount DESC, cs.candidate_id ASC
;
  • 您可以使用HAVING candidateSkillCount = requiredSkillCount子句仅获取完全合格的子句(或<获取部分合格的子句),
  • 您可以加入candidates表以获取候选人的姓名
  • 您可以加入skills表以使用GROUP_CONCAT(skills.name ORDER BY skills) AS relevantSkillsList来获得结果中以逗号分隔的技能列表(如果您想命名,则需要两次加入)所需技能和所拥有技能的列表)

答案 1 :(得分:-1)

这将对您有帮助

Imports System.Drawing.Imaging

Sub CreateTiff(sOutTiffFile As String, sInFile1 As String, sInFile2 As String)
    Dim bitmap As Bitmap = Image.FromFile(sInFile1)
    Dim byteStream As MemoryStream = New MemoryStream()
    bitmap.Save(byteStream, System.Drawing.Imaging.ImageFormat.Tiff)

    Dim tiff As Image = Image.FromStream(byteStream)

    Dim oParams As EncoderParameters = New EncoderParameters(2)
    oParams.Param(0) = New EncoderParameter(Imaging.Encoder.Compression, EncoderValue.CompressionCCITT4)
    oParams.Param(1) = New EncoderParameter(Imaging.Encoder.SaveFlag, EncoderValue.MultiFrame)
    tiff.Save(sOutTiffFile, GetEncoderInfo("image/tiff"), oParams)

    'Next Page
    Dim bitmap2 As Bitmap = Image.FromFile(sInFile2)
    oParams.Param(1) = New EncoderParameter(Imaging.Encoder.SaveFlag, EncoderValue.FrameDimensionPage)
    tiff.SaveAdd(bitmap2, oParams)

    'Flush 
    Dim oFlushParams As EncoderParameters = New EncoderParameters(1)
    oFlushParams.Param(0) = New EncoderParameter(Imaging.Encoder.SaveFlag, EncoderValue.Flush)
    tiff.SaveAdd(oFlushParams)
End Sub

Private Function GetEncoderInfo(mimeType As String) As System.Drawing.Imaging.ImageCodecInfo
    Dim encoders = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()
    For i As Integer = 0 To encoders.Length - 1
        If encoders(i).MimeType = mimeType Then
            Return encoders(i)
        End If
    Next
    Return Nothing
End Function