dousi1906 2014-02-12 12:36
浏览 60

在PHP / MYSQL中计算过滤器记录[重复]

This question already has an answer here:

I have a PHP/MYSQL based application in which there is a search area, when you search by dates then I show that a property/hotel is available between those dates. Also I have some other filters like area, facilities that Hotel has etc.

Now as of now everything working ok, but cutsomer now wants to show the number of records in bracket for each filter.

I tried it by adding multiple queries for each filter based on dynamic search user did, but that making my page performance slow. Because if I have 5 filters then I will run 5 queries.

I have seen such thing in magento, it counts the number of result that filter have as shown in picture below:

enter image description here

What will be the best method of doing this, I just need some logic and procedure which can be followed to resolve this.

Posting whole table structure is difficult, but I am positing shorter for of it, so you guys may have some idea and suggest some solution:

Tables are:

Properties - id, name
Factsheet_label - label_id, Name
Factsheet - id, label_id, prop_id, value (Yes, No)

I am showing all the filters from factsheet_label table and then I need to count the result of properties I have.

</div>
  • 写回答

3条回答 默认 最新

  • doukuang8166 2014-02-12 12:42
    关注

    Every "SELECT *" can be a "SELECT *, COUNT(*) ...." then you can see the nr of the results. To help you more I need to see the code.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝