gpt4 book ai didi

php - 如何使用 php 和 mysql 显示 future 30 天的数据?

转载 作者:行者123 更新时间:2023-11-29 14:47:13 25 4
gpt4 key购买 nike

有一个 jquery.ui.datepicker 如下:

<script type="text/javascript">
$(function() {
$("#datepicker").datepicker({
minDate: 'today',
maxDate: "+90D",
showOn: "button",
buttonImage: "images/calendar-new2.jpg",
buttonImageOnly: true,
dateFormat: "D, dd M, yy"
});
});
</script>

并获取包含在表单中的日期日期选择器,如下所示:

<form method="post"><input align="center" type="hidden" id="datepicker" onChange="this.form.submit();" name="datepicker" value=""/></form>

下面是从mysql表中调用数据:

<?php
$today = date('D, d M, Y');
$sql = "SELECT * FROM postings WHERE day1 = '$today' AND city = 'New York' OR day2 = '$today' AND city='New York' OR day3 = '$today' AND city='New York' OR day4 = '$today' AND city='New York' OR day5 = '$today' AND city='New York' OR day6 = '$today' AND city='New York' OR day7 = '$today' AND city='New York' OR day8 = '$today' AND city='New York' OR day9 = '$today' AND city='New York' OR day10 = '$today' AND city='New York'";
if($_POST!=""){
$mydate = mysql_real_escape_string($_POST['datepicker']);
if($mydate!=""){
$sql = "SELECT * FROM postings WHERE day1 = '$mydate' AND city = 'New York' OR day2 = '$mydate' AND city='New York' OR day3 = '$mydate' AND city='New York' OR day4 = '$mydate' AND city='New York' OR day5 = '$mydate' AND city='New York' OR day6 = '$mydate' AND city='New York' OR day7 = '$mydate' AND city='New York' OR day8 = '$mydate' AND city='New York' OR day9 = '$mydate' AND city='New York' OR day10 = '$mydate' AND city='New York'";
}
}
if($mydate) {
echo "New York - $mydate";
}
else {
echo "New York - $today";
}
$num_results_per_page = 8;
$num_page_links_per_page = 5;
$pg_param1 = ""; // Ex: &q=value
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
pagination($sql, $num_results_per_page, $num_page_links_per_page, $pg_param);
if($pg_error == '')
{
if(mysql_num_rows($pg_result) > 0)
{
while($data = mysql_fetch_assoc($pg_result))
{
echo "
-------
--------
-----
";
?>

此查询将显示今天的数据或根据用户点击的日期显示的数据。

请帮助我解决以下问题:1) 下一个和上一个按钮,如果单击则显示前几天的数据和后几天的数据。2)显示 future 7天的数据。

最佳答案

您的查询效率极低。这会工作得更好并且更容易准备:

$date = (isset($_POST['datepicker'])) ? "'" . mysql_real_escape_string($_POST['datepicker']) "'" : 'now()';

SELECT * FROM postings
WHERE (city = 'New York') and
$date IN (day1, day2, day3, day4, day5, day6, day7, day8, day9, da10);

对于接下来的 7 天,只需执行以下操作:

WHERE ...
DATE_ADD($date, INTERVAL 7 DAY) IN (....)

关于php - 如何使用 php 和 mysql 显示 future 30 天的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6695325/

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