我正在使用PHP和MySQL开发一个系统。
我的一个表单会提示用户填写两个文本框,即startTime
和endTime
。用户必须填写文本框并在提交时将其插入名为Slot
的表中,并将其与先前的数据一起输出。
5:30
6:00
6:30
7:00
7:30
8:00
我该怎么办?引导我回答你的问题。 这是我的代码:
$i=0;
$sid=1;
$appointmentsdate=$_REQUEST['sTime'];
$appointmentedate=$_REQUEST['eTime'];
for($appointmentsdate;$appointmentsdate<$appointmentedate;$appointmentsdate++)
{
$arrayStartTime[$i]="{$appointmentsdate}:00";
$i++;
$arrayStartTime[$i]="{$appointmentsdate}:30";
$i++;
}
echo "<pre>";
print_r($arrayStartTime);
die;
for ($k=0; $k<sizeof($arrayStartTime); $k++)
{
SJB_DB::query('insert into `schedule_slot` (`schedule_id`,`startTime`,`endTime`) values
(?s,?s,?s)',$sid,$arrayStartTime[$k],$arrayStartTime[$k+1]);
}
提前谢谢。
答案 0 :(得分:0)
#your inputs
$start = "11:00";
$time_end = "13:30";
#converting them to timestamps
$time_start = strtotime($start);
$time_end = strtotime($time_end);
#looping
while($time_start <= $time_end){
$someArr[] = date("H:i",$time_start)."\n";
$time_start = strtotime('+30 minutes',$time_start);
}
将它集成到当前代码中,应该看起来像(未经测试):
$i=0;
$sid=1;
$appointmentsTimeStart = strtotime($_REQUEST['sTime']);
$appointmentsTimeEnd = strtotime($_REQUEST['sTime']);
for($appointmentsTimeStart; $appointmentsTimeStart<$appointmentsTimeEnd; $appointmentsdate1++)
{
$arrayStartTime[$i] = date("H:i", $appointmentsTimeStart);
$appointmentsTimeStart = strtotime('+30 minutes',$appointmentsTimeStart);
$i++;
}
print_r($arrayStartTime);