ai didi

php - 如何合并多个select语句

转载 作者:行者123 更新时间:2023-11-29 14:46:58 24 4
gpt4 key购买 nike

以下查询:

$today = date('Y-m-d');
$sql = "SELECT * FROM table WHERE day1 = '$today' AND country = 'India' OR day2 = '$today' AND country = 'India' OR day3 = '$today' AND country = 'India' OR day4 = '$today' AND country = 'India' OR day5 = '$today' AND country = 'India' OR day6 = '$today' AND country = 'India' OR day7 = '$today' AND country = 'India' OR day8 = '$today' AND country = 'India' OR day9 = '$today' AND country = 'India' OR day10 = '$today' AND country = 'India'";
if($_POST!=""){
$mydate = mysql_real_escape_string($_POST['datepicker']);
if($mydate!=""){
$sql = "SELECT * FROM table WHERE day1 = '$mydate' AND country = 'India' OR day2 = '$mydate' AND country = 'India' OR day3 = '$mydate' AND country = 'India' OR day4 = '$mydate' AND country = 'India' OR day5 = '$mydate' AND country = 'India' OR day6 = '$mydate' AND country = 'India' OR day7 = '$mydate' AND country = 'India' OR day8 = '$mydate' AND country = 'India' OR day9 = '$mydate' AND country = 'India' OR day10 = '$mydate' AND country = 'India'";
}
}
.......
........
echo"......
......
......

它与日期选择器链接。仅在同一页面中回显。想要在同一页面中添加以下选择语句....如果用户单击“接下来 10 天的计划”。

select * from table WHERE (day1 >= CURRENT_TIMESTAMP
AND country = 'India'
AND day1 <= CURRENT_TIMESTAMP + INTERVAL 10 DAY
AND country = 'India')
OR
(day2 >= CURRENT_TIMESTAMP
AND country = 'India'
AND day2 <= CURRENT_TIMESTAMP + INTERVAL 10 DAY
AND country = 'India')

......till day10

最佳答案

SELECT * FROM table 
WHERE (
(day1 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day2 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day3 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day4 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day5 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day6 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day7 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day8 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day9 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
OR (day10 BETWEEN NOW() AND NOW() + INTERVAL 10 DAY)
)
AND country = 'India'

关于php - 如何合并多个select语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6758591/

24 4 0
文章推荐: javascript - 在 Knockout JS foreach 循环中围绕每个 'n' 项放置一个容器
文章推荐: android - 当我们将最小 API 设置为 7 时,如何使用更高的 API
文章推荐: javascript - React TestUtils 不适用于装饰器或如何使用 rewire 模拟高阶函数
文章推荐: Android 谷歌地图 V2 删除单个标记
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com