简体   繁体   中英

how to refine/filter search result from mysql database using php?

i am trying to develop my website and need some support. so my web page searches for a product's information and return an appropriate result.It works perfectly fine when user search through a keyword or product title in search box and submit the query but now with the list of result obtained, i want a filter search where the user is able to filter their search result according to price, brand, category, etc.

i have two tables in the mysql database 1 : product_info with columns productid, title, description, brand, category, price 2: product_image productid,imageid,imagename,image

please help me on how about i should begin with the process. i have looked on net and their are multiple suggestions on which script to use but i want to work with the simplest approach since i am new to all this. you can suggest anything related to this topic.Thank you:)

just to let you know, for single search box i used the following code.

$query= "
    SELECT * 
    FROM `product_info`
    WHERE `title` LIKE '% ".$search_name." %'
    OR `title` LIKE '% ".$search_name."'
    OR `title` LIKE '".$search_name." %'
    OR `title` = '".$search_name."'";

    $query_run=mysql_query($query);


    if(mysql_num_rows($query_run)>=1) 

    {
        echo'Showing '.mysql_num_rows($query_run).' results for items with "'.$search_name.'" in    the title:';

//the result is displayed in the table format.

}

The answer is that you don't use php for this. The whole idea of having a database is that you run queries against it in order to select data from it based on criteria. So you build a suitable WHERE clause for your query which will pull only the rows that match the criteria requested by the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM