我一直在抨击论坛,发现帖子类似,但对我不起作用,所以这里有。
我正在尝试两件事,首先:我创建了一个复选框,选中后会显示商店的结果。 shop_open
和shop_close
是我在此使用的列,其中time
数据类型(例如07:00:00
)。当用户选中并提交带有复选框的表单时,我希望CURTIME()
之类的内容仅检查当前时间,小时和分钟,然后查看当前时间:分钟是否在shop_open
和shop_close
次,应显示当时提交的商店。
第二个选项是让2个输入框进入打开和/或关闭时间,以查看数据是否与上述类似。第一个选项对我来说听起来更好,摆弄2个选项导致了后退步骤。
这是我的问题:
"SELECT shops.*, services.*, ratings.*, 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 + spacious + experience )/(6) / 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 CURTIME() BETWEEN shop_open AND shop_close
AND address LIKE '%$search_shop_address%' AND shop_name LIKE '%$search_shop_name%' ORDER BY shop_name ASC
我知道这是一个混乱而复杂的查询,但它可以很好地减去这个问题。 您建议的代码,我已经在使用但在不同的情况下,因为我的混乱查询混乱,我想我把它放在了错误的地方:s
我不想使用 '$ search_open_now'BETWEEN shop_open AND shop_close 而不是获得当前时间,它返回错误的结果:(
答案 0 :(得分:3)
这样的事情会做我认为你想要的事情:
SELECT * FROM yourtable WHERE CURTIME() BETWEEN shop_open AND shop_close;
答案 1 :(得分:2)
SELECT field_names FROM table_name WHERE CONCAT(DATE_FORMAT(NOW(), '%H:%i'), ':00') BETWEEN shop_open AND shop_close
应该忽略你的秒数。
更新:这样的东西似乎对我有用,在HAVING子句之前移动WHERE
SELECT shops.*, services.*, ratings.*, 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 + spacious + experience )/(6) / COUNT(shop_id) AS total, shop_id FROM ratings GROUP BY shop_id ) as temp on shops.shop_id=temp.shop_id
WHERE CONCAT(DATE_FORMAT(NOW(), '%H:%i'), ':00') BETWEEN shop_open AND shop_close
HAVING temp.total >= '$search_total_rating'
AND address LIKE '%$search_shop_address%' AND shop_name LIKE '%$search_shop_name%' ORDER BY shop_name ASC