我正在尝试创建搜索页面,这是我的查询。我有3张桌子,“服务”,“收视率”和“商店”。 '商店'包含88个结果,而'评级'包含93,当使用时: $ nr = mysql_num_rows($ result); 它返回了93,而不是像我预期的那样88,如何归还88家商店,它实际上是对于超过1个评级的商店的结果加倍。例如:如果商店有2票,商店会出现两次。
$result = mysql_query("SELECT services.*, ratings.*, shops.*, temp.total as final_total,
CONCAT(shop_number, ' ', shop_location, ' ', shop_city, ' ', shop_province, ' ', shop_postcode) AS address FROM shops
inner join services on shops.shop_id=services.shop_id
inner join ratings on shops.shop_id=ratings.shop_id
inner join (select SUM(comfort + service + ambience + friendliness)/(12) / COUNT(shop_id) AS total, shop_id FROM ratings GROUP BY shop_id ) as temp on shops.shop_id=temp.shop_id
HAVING temp.total >= '$search_total_rating'
AND address LIKE '%$search_shop_address%'
AND shop_name LIKE '%$search_shop_name%'
AND comfort >= '$search_shop_comfort'
AND service >= '$search_shop_service'
AND ambience >= '$search_shop_ambience'
AND friendliness >= '$search_shop_friendliness'
ORDER BY shop_name ASC");