我有一个问题,找不到任何解决方案。我正在尝试制作一个页面,以在特定剧院和特定时间将节目添加到特定电影中。我需要创建一个功能来检查上一个或下一个节目的时间,并检查是否可以为具有特定持续时间的电影添加节目
例如:电影时长 2 小时节目 1 : 1 PM 在下午 2 点添加节目时,会出现错误,因为下午 1 点的节目尚未结束。
我相信我的问题是日期时间格式!因为我没有收到错误...页面正在运行但数据类型输入不正确
编码:
require('classes/show_class.php');
$valid_show = show::check_time_validity($showdatetime,$movieid, $theaterid);
if( $valid_show !== true )
{
echo $valid_show['error'];
exit;
}
$querycinema=mysql_query(
"SELECT show.show_datetime, show.theater_id, show.movie_id, theater.theater_name, movie.movie_name
FROM `show`
JOIN theater ON theater.theater_id = show.theater_id
JOIN movie ON movie.movie_id = show.movie_id
WHERE show.show_datetime='$showdatetime' AND show.theater_id='$theaterid' AND show.movie_id='$movieid'"
);
$checkcinema = mysql_num_rows( $querycinema );
if( $checkcinema != 0 )
{
$data = mysql_fetch_assoc( $querycinema );
echo "Sorry, ".$showdatetime." is already been scheduled for movie ".$data['movie_name']." in theater ".$data['theater_name'].".";
}
else
{ echo "$selected_show_time";
$insert_user = mysql_query("INSERT INTO `show` (show_datetime, movie_id, theater_id) VALUES ('$showdatetime','$movieid', '$theaterid')");
if( $insert_user )
{
header("Refresh: 0;url=listallshows.php");
}
else
{
echo "error in registration".mysql_error();
}
}
}
和 show_class.php 函数:
public static function check_time_validity($show_datetime,$movie_id, $theater_id)
{
$show_date = date($show_datetime);
$query = "
(
SELECT show_datetime
FROM `show`
WHERE movie_id = {$movie_id} AND theater_id = {$theater_id} AND DATE( show_datetime ) = '{$show_date}' AND '{$show_datetime}' >= show_datetime
ORDER BY show_datetime DESC
LIMIT 1
)
UNION
(
SELECT show_datetime
FROM `show`
WHERE movie_id = {$movie_id} AND theater_id = {$theater_id} AND DATE( show_datetime ) = '{$show_date}' AND '{$show_datetime}' <= show_datetime
ORDER BY show_datetime ASC
LIMIT 1
)";
$results = mysql_query( $query );
$selected_show_time = strtotime( $show_datetime );
$show_times = array();
while( $show = mysql_fetch_assoc( $results ) )
{
$show_time = strtotime( $show['show_datetime'] );
if( $selected_show_time == $show_time )
{
return array( 'error' => 'Datetime inserted already exists' );
}
if( $selected_show_time > $show_time )
{
$show_times['time_before'] = $show_time;
}
elseif( $selected_show_time < $show_time )
{
$show_times['time_after'] = $show_time;
}
}
$movie = new movie($movie_id);
$movie_duration = $movie->duration;
$can_begin = true;
$can_finish = true;
$errorMessage = array();
if( $show_times['time_before'] )
{
$finish_time = $show_times['time_before'] + $movie_duration;
if( ( $selected_show_time - $finish_time ) < '15' )
{
$can_begin = false;
$errorMessage = array( 'error' => 'The datetime selected is in conflict with the previous show' ); echo "$selected_show_time"; echo"$finish_time";exit;
}
}
if( $show_times['time_after'] )
{
$finish_selected_time = $selected_show_time + $movie_duration;
if( ( $show_times['time_after'] - $finish_selected_time ) < '15' )
{
$can_finish = false;
$errorMessage = array( 'error' => 'The datetime selected is in conflict with the next show' );
}
}
if( $can_begin && $can_finish )
{
return true;
}
else
{
return $errorMessage;
}
}
希望得到任何帮助谢谢。。