dongpu8935 2013-03-06 22:35
浏览 61

如何使用php从mysql数据库中优化/过滤搜索结果?

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.

}
  • 写回答

1条回答 默认 最新

  • duadlkc5762218 2013-03-06 22:55
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?