du6jws6975 2014-01-25 19:09
浏览 33
已采纳

PHP:多文本搜索

So , i got a form to search for jobseeker through the database . The form contain name , identity card , job position , academic certificate , age etc . The problem that i'm facing is when i'm searching for jobseeker based only on one text form for example , job position , the result is shown . But , if i want to search for jobseeker based on job position and academic level , the result is shown based on job position only . Is there anything wrong with my code ? need help here .. sorry for my bad english though ..

for job position :

$jawatan_arr = explode(',', $_POST['txt_jawatan']);
$jum_jawatan = count($jawatan_arr);
//echo "jum_didik = ".$jum_didik;
if($jum_jawatan > 0){
    $d = 0;
    foreach ($jawatan_arr as $value){
        $d++;
        //echo "; value::: ".$value." :::";
        if($d == 1){
            if($value != ''){
                if($str == ''){
                    $str = " WHERE ";   
            }
                else{
                    $str .= " AND ";    
            }
                $str_jawatan .= " (LOWER(jawatan) LIKE '%".strtolower(rtrim(ltrim($value)))."%' ";
            }
        }
        else{
            if($value != ''){
                $str_jawatan .= " OR LOWER(jawatan) LIKE '%".strtolower(rtrim(ltrim($value)))."%' ";
            }
        }
    }
    if($str_jawatan != ''){
        $str_jawatan .= ") ";

        $sql = "SELECT no_kp FROM jobseeker_pengalaman ".$str_jawatan;
        $res = mysql_query($sql);
        while($row = mysql_fetch_array($res)){
            if($row['no_kp'] != ''){
                if(!in_array($row['no_kp'], $senarai_kp)){
                    array_push($senarai_kp, $row['no_kp']); 
                }
            }
        }
    }
}

for academic level(checkbox , not a textform) :

$didik_arr = explode(',', $_POST['txt_taraf_pendidikan']);
$jum_didik = count($didik_arr) - 1;
//echo "jum_didik = ".$jum_didik;
if($jum_didik > 0){
    $d = 0;
    foreach ($didik_arr as $value){
        $d++;
        //echo "; value::: ".$value." :::";
        if($d == 1){
            if($str == ''){
                    $str = " WHERE ";   
            }
            else{
                $str .= " AND ";    
            }
            $temp_didik .= $value;
        }
        else{
            if($value != ''){
                $temp_didik .= ",".$value;
            }
        }
    }

    //$str_didik .= " id_taraf_pendidikan IN (".$temp_didik.")";

    $sql = "SELECT no_kp FROM jobseeker_pendidikan WHERE id_taraf_pendidikan IN (".$temp_didik.")";

    $res = mysql_query($sql);
    while($row = mysql_fetch_array($res)){
        if($row['no_kp'] != ''){
            if(!in_array($row['no_kp'], $senarai_kp)){
                array_push($senarai_kp, $row['no_kp']); 
            }
        }
    }
}

Do i need to join the my table ? because the job position is based on recent job experience , and academic is based on their study . Both of them are from different table

  • 写回答

1条回答 默认 最新

  • ds2010630 2014-01-25 23:08
    关注

    May be you can try IN statement? Something like this:

    $sql = "SELECT no_kp FROM jobseeker_pengalaman ".$str_jawatan." IN
    (
     SELECT no_kp FROM jobseeker_pendidikan WHERE id_taraf_pendidikan IN (".$temp_didik.")
    )";
    

    So you will search by job positions within that jobseekers that already passed through your academic based search. I hope this approach will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器