我试图写一个脚本来拉日期未来7天,并把它们放到一个div对于每一日期,接下来5天:获取预约使用PHP
echo '<div class="dateboxcontainer">';
for($i=0; $i<=6; $i++){
echo '<div class="datebox"><div class="topdate">'.strtoupper(date("D d", mktime(0, 0, 0, 0, date("d")+$i, 0))."\n").
'</div><div class="bottomdate">An appointment for the day</div></div>';
}
echo '</div>';
林现在想从我的数据库由两场“datedroppingoff”和“datepickingup”,这是此格式“2013年7月10日14时29分28秒”中提取数据。
林种坚持,虽然作为即时通讯不知道该写什么查询把约会每天到每一天的div其中,“一些信息”目前是。
即时猜测它会是这样的
Select * FROM jobdetails WHERE datedroppingoff OR datepickingup = WHATEVER DAY IS BEING ECHO'D OUT
,但即时通讯不能肯定我怎么可以比较被回显出存储在jobdetails该行的日期的日期?
编辑>>>>>
感谢下面的答案,四设法想出下面,回声出日期框好,但犯规中的任何数据带来的,所以如果我林不知道SQL部分是否正确?
echo '<div class="dateboxcontainer">';
$eventdata = <<<SQL
SELECT *
FROM `jobdetails`
SQL;
if(!$events = $db->query($eventdata)){
die('There was an error running the query [' . $db->error . ']');
}
// read first event
if ($nextEvent = mysql_fetch_assoc($events)) { // here is the first one
extract($nextEvent); // prepare its variables
// use the event date it to control the inner loop
$nextDate = $datedroppingoff;
} else // no events?
$nextDate = 0; // prepare a fake date value
// calculate today date
$currentDate = mktime();
// loop on the dates for the next 7 days
for ($i = 0 ; $i < 7; $i++) {
$currentEvents = "";
// loop to print every event for current day (first one already extracted)
while ($nextDate == date("Y-m-d", $currentDate)) { // next event occurs today
// here prepare the var containing the event description
// BTW, I'd use a list for the events
$currentEvents .= "· $name<br>"; // use every field you need from current DB row
// read next event
if ($nextEvent = mysql_fetch_assoc($events)) { // here is the next one
extract($nextEvent); // prepare its variables
// use the event date it to control the inner loop
$nextDate = $datedroppingoff;
} else // no more events?
$nextDate = 0; // prepare a fake date value
}
echo "
<div class='datebox'>
<div class='topdate'>" . strtoupper(date("D d m Y", $currentDate)) . "</div>
<div class='bottomdate'>$currentEvents</div>
</div>";
$currentDate = strtotime("+1 day", $currentDate);
}
echo '</div>';
'WHERE(日期(datedroppingoff)> = 'STARTDATE' 和日期(datedroppingoff)<= '结束日期')OR(日期(datepickingup)> = 'STARTDATE' 和日期(datepickingup)<=' enddate')'..为了便于格式化,请查看'DateTime'和可能的'DateInterval'对象。 – Wrikken
但是,如何在未来7天将其添加到for循环中,那就是即时通讯有什么问题? –