php mysql在十个表+不同的列上构建搜索查询

时间:2012-12-14 12:27:03

标签: php mysql

我正在尝试为网站开发搜索页面,但无法提出单个查询。

以下是这十个表及其字段的列表

  1. tmp_auction_auto

    id订单类别制造商型号价格price_type位置年份run_type门安全气囊齿轮发动机马力气缸驱动器燃料颜色abs电子窗口climatcontrol磁盘舱口板计算机报警器turte parkingcontrol调节器leathersalon导航中央锁定椅子水力学noprice租赁交换定制状态其他联系

  2. tmp_auction_estate id订单类型交易价格price_type price_sqm noprice城市地址区高度维修条件项目目的地土地阳台有双重斜坡屋顶会议stairs_total楼梯室卧室阳台sanitary_arr凉廊壁炉空调车库停车land_destination建筑物distance_central_street distance_tbilisi库房按摩浴室浴室淋浴桑拿家具技术电话互联网发电机池businesscenter吃网络库存wardobe电梯燃气热水加热对讲电缆报警系统入口安全窗口防盗安全双工三联卫星厨房展示land_railway land_electricity land_gas land_water land_drainage status其他联系

  3. tmp_auction_other id订单标题价格price_type noprice info contact

  4. tmp_branch id lang title content x y
  5. tmp_comments id reply_id路径用户名电子邮件标题内容喜欢不喜欢时间管理员
  6. tmp_news id lang title content date

  7. tmp_pages id lang title content date

  8. tmp_polls id name question answers ip

  9. tmp_presentation id lang title order

  10. tmp_sitemap id parent lang title link order

  11. 我知道我可以用任何顺序(不良做法)为每个表写多个查询,然后将它组合到PHP数组中进行输出,但我更需要专业的方法来处理这个主题。

    P.S。我不想使用memcache,solr,sphinxs等libs(服务器不支持那些)

    • 我也会感谢其他搜索建议,如内容搜索等(网站是用mvc模式写的,用url重写并依赖于mysql数据库)

1 个答案:

答案 0 :(得分:1)

I guess you can join these tables and create a view into which the data obtained fom the joined tables can be saved. Now the search must be conducted on this view which will speed up the search.
For eg.
mysql> SELECT CONCAT(UPPER(supplier_name), ' ', supplier_address) FROM suppliers;
+-----------------------------------------------------+
| CONCAT(UPPER(supplier_name), ' ', supplier_address) |
+-----------------------------------------------------+
| MICROSOFT 1 Microsoft Way                           |
| APPLE, INC. 1 Infinate Loop                         |
| EASYTECH 100 Beltway Drive                          |
| WILDTECH 100 Hard Drive                             |
| HEWLETT PACKARD 100 Printer Expressway              |
+-----------------------------------------------------+
CREATE VIEW suppformat AS 
SELECT CONCAT(UPPER(supplier_name), ' ', supplier_address) FROM suppliers;

mysql> SELECT * FROM suppformat;
+-----------------------------------------------------+
| CONCAT(UPPER(supplier_name), ' ', supplier_address) |
+-----------------------------------------------------+
| MICROSOFT 1 Microsoft Way                           |
| APPLE, INC. 1 Infinate Loop                         |
| EASYTECH 100 Beltway Drive                          |
| WILDTECH 100 Hard Drive                             |
| HEWLETT PACKARD 100 Printer Expressway              |
+-----------------------------------------------------+


Please check this link which will give you some idea of views
[http://www.techotopia.com/index.php/An_Introduction_to_MySQL_Views][1]


  [1]: http://www.techotopia.com/index.php/An_Introduction_to_MySQL_Views