gpt4 book ai didi

php - sql查询中的多个条件

转载 作者:行者123 更新时间:2023-11-30 21:23:12 25 4
gpt4 key购买 nike

我想提取日期类似于今天的记录。

我有这个问题

$query = "select * from calendar_items WHERE expiredate LIKE '$todays_date %' 
or upcoming_event_featured_date like '$todays_date %'
ORDER BY expiredate ASC";

现在我还有 3 个即将到来的_event_featured_date:即将到来的_event_featured_date2、即将到来的_event_featured_date3、即将到来的_event_featured_date4

所以我想运行一个查询,该查询将获取日期与四个即将到来的_event_featured_date(upcoming_event_featured_date、即将到来的_event_featured_date2、即将到来的_event_featured_date3、即将到来的_event_featured_date4)的日期相似的结果。

查询看起来像这样吗?

$query = "select * from calendar_items 
WHERE expiredate LIKE '$todays_date %' or
(upcoming_event_featured_date like '$todays_date %' or
upcoming_event_featured_date2 like '$todays_date %' or
upcoming_event_featured_date3 like '$todays_date %' or
upcoming_event_featured_date4 like '$todays_date %')
ORDER BY expiredate ASC";

最佳答案

你绝对应该听听 HLGEM 并规范化表结构。但是对于您所要求的,假设 $todays_date 是实际日期(如 2009-11-16),该查询可能会起作用。不过,您可能需要将 % 移得更近一些,以更安全一些:

$query = "select * from calendar_items 
WHERE expiredate LIKE '{$todays_date}%' or
(upcoming_event_featured_date like '{$todays_date}%' or
upcoming_event_featured_date2 like '{$todays_date}%' or
upcoming_event_featured_date3 like '{$todays_date}%' or
upcoming_event_featured_date4 like '{$todays_date}%')
ORDER BY expiredate ASC";

关于php - sql查询中的多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1744389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com