带有筛选器列表的php搜索栏

时间:2015-04-20 16:25:21

标签: php mysql

我有一个找到工作的搜索栏,我希望有机会根据所选城市或/和类别过滤结果。

到目前为止,这是我的PHP代码:

if (isset($_POST['search'])) {
    $job = $_POST['search'];
    $city = $_POST['city'];
    $category = $_POST['category']; 

    $query ="SELECT jobname, city, category FROM table_jobs WHERE jobname LIKE '%$job%'";

    if($city != "Chose City") {
        $query .=" AND city LIKE '%$city%'";
    }
    if($ategory != "Chose Category"){
        $query .=" AND category LIKE '%$category%'";
    }

    $sql = mysql_query($query);
    $count = mysql_num_rows($sql);

    if ($count == 0) {
        $output = "No results!";
    } else {
        while($row = mysql_fetch_array($query)) {
            $titlu = $row['jobname'];
            $companie = $row['numefirma'];
            $oras = $row['numeoras'];   
            $domeniu = $row['numedomeniu'];

             $output .=<<<HTML
             <table id="anunt">
             <tr>
             <td class='left'><a href='' style="color: blue">$titlu</a><br>Companie:        $companie<br>Domeniu: $domeniu</td>
             <td class='right'>$oras</td>
             </tr>
             </table>
             HTML;
        }
     }
 }

搜索栏看起来像this

如何使我的过滤列表有效?我在我的数据库和类别表中有我的城市表(包括IT软件,营销等工作类别)

0 个答案:

没有答案