使用选择标记和输入字段进行搜索

时间:2013-03-14 04:22:48

标签: php mysql jquery

这是我的Table1

table1

这是我的Table2 enter image description here 这是选择字段和输入搜索字段的表单

<form name="search_form" method="get" action="">
    <div class="search_job">
        <div class="heading">
            Search Jobs:
        </div>
        <?php $jobcat = DAOFactory::getTblCategoriesDAO()->queryAll();
        ?>
        <select name="loctopcities" id="loctopcities" class="job_place_input" >
            <option value="" >Select Job Type</option>
            <?php for($k=0;$k<count($jobcat);$k++){
            ?>
            <option id = "catName" value="<?php echo $jobcat[$k]->categoryName; ?>" ><?php echo $jobcat[$k]->categoryName; ?></option>
            <?php } ?>
        </select>
        <input  class="job_area_input populate" name="key" id="key"  type="text"  onKeyUp="suggest_jobs(this.value);" onBlur="fill_reguser();" >
        <input name="btn_submit" value="Search" class="search_button" type="submit" >
        <div class="suggestionsBox" id="suggestions" style="display: none;">
            <div class="suggestionList" id="suggestionsList">
            </div>
        </div>
    </div>
</form>

这里是搜索建议的脚本

<script>
function suggest_jobs(inputString,selectString){
    if(inputString.length == 0 ){
        $('#suggestions').fadeOut();
    } else {
        $('#key').addClass('load')
        $('#catName').addClass('load')
        $.post("suggestionforjobs.php", {queryString: ""+inputString+"",catName: ""+selectString+""}, function(data){
            //alert("testing : "+data+" :: data length : "+data.length)
            if(data.length >10) {
                $('#suggestions').fadeIn()
                $('#suggestionsList').html(data)
                $('#key').removeClass('load')
                $('#catName').removeClass('load')
            } else {
                $('#suggestions').fadeOut()
                $('#key').removeClass('load')
                $('#catName').removeClass('load')
            }
        });
    }
}
function fill_reguser(thisValue) {
    $('#key').val(thisValue);
    setTimeout("$('#suggestions').fadeOut();", 1000);
}
</script>

以下是suggestionforjobs.php

的代码
<?php
include_once("include_dao.php");
if(isset($_POST['queryString']) ||  isset($_POST['catName']) ) 
{
    $value = $_POST['queryString'];
    $catname = $_POST['catName'];
    if(strlen($queryString) >0) 
    {
        $c = DAOFactory::getTblJobsDAO()->querysearchjobs($value,$catname);
        $countm=count($c);
        if($c) 
        {
            echo '<ul>';
            for($m=0;$m<$countm;$m++)
            {
            ?>
            <li onClick="fill_reguser('
            <?PHP echo $c[$m]->jobPosition; ?>')">
                <?PHP echo $c[$m]->jobPosition; ?> 
            </li>
            <?php
            }
            echo '</ul>';
        } else {
            echo 'No Related Search Content Available with this starting letter';
        }
    } else {
        // do nothing
    }
} else {
    echo 'There should be no direct access to this script!';
}
?>

我的查询是"SELECT * FROM tbl_jobs cc INNER JOIN tbl_categories c ON cc.job_category_id = c.category_id WHERE job_position LIKE '%$value%' AND c.category_name LIKE '%$catname%' ORDER BY job_id"

我需要的是什么? 如果我在选择框中选择一个值,它应该传入查询(c.category_name LIKE'%$ catname%'),因为一些代码要用脚本编写,一切正常,除了(catName:“”+ selectString +“”)在脚本中。 所以任何人都可以用完美的jquery脚本帮助我。 感谢提前

1 个答案:

答案 0 :(得分:0)

SELECT * FROM tbl_jobs cc INNER JOIN tbl_categories c ON cc.job_category_id = c.category_id WHERE job_position LIKE '%$value%' AND (column name) LIKE '%$value%' ORDER BY job_id"