dtczp02204 2014-05-28 06:18
浏览 44
已采纳

使用php和mysql搜索查询[关闭]

Need help on how to filter search results in the search form using PHP and Mysql.

The form contains six fields Product is textbox, Category is drop down select item, Business in text box user enters and state, city are drop down select item and Landmark is textbox the user enters.

Product or Category or Business is mandatory. So the user may enter any one filed or may fill all the fields.

Now I need to get exact search result based on the input. Please Help me to solve this

  • 写回答

1条回答 默认 最新

  • doujiao1949 2014-05-28 06:45
    关注

    Try this:

    $query = "select * from table_name where 1 ";
    
    if(!empty($_POST['field1']) ) {
       $query .= " AND field1 like '".trim($_POST['field1'])."'";
    }
    if(!empty($_POST['field2'])) {
       $query .= " AND field2 like '".trim($_POST['field2'])."'";
    }
    // and so on
    $result = mysql_query($query);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?