左连接影响其他PHP

时间:2016-08-19 07:53:10

标签: php mysql

您好我想显示port_name而不是端口ID($ row ['port_name'])所以我做了这个查询。

$stmt = $db->prepare("SELECT * FROM reservations 
INNER JOIN ports ON   reservations.port=ports.id WHERE NOT
((end <= :start) OR (start >= :end))");
$stmt->bindParam(':start', $_POST['start']);
$stmt->bindParam(':end', $_POST['end']);
$stmt->execute();
$result = $stmt->fetchAll();

class Event {}
$events = array();

date_default_timezone_set("UTC");
$now = new DateTime("now");
$today = $now->setTime(0, 0, 0);

foreach($result as $row) {

$e = new Event();
$e->id = $row['id'];
$e->service_id = $row['service_id'].'<br/>';
$e->service_classification = $row['service_classification'].'<br/>';
$e->text = $row['port_name'].'<br/>';
$e->start = $row['start'];
$e->end = $row['end'];
$e->resource = $row['room_id'];
$e->customer = $row['customer'];

$events[] = $e;
}
header('Content-Type: application/json');
echo json_encode($events);

?>

它正在工作并向我展示它应该的端口名称,但是当我想要移动事件或调整我的事件大小(我有“事件”的日历)然后我刷新页面事件保持在以前的位置。当我删除JOIN并离开port_id(reservations.port)时,一切正常!

resize.php:

class Result {}

$stmt = $db->prepare("UPDATE reservations SET start = :start, end = :end WHERE id = :id");
$stmt->bindParam(':id', $_POST['id']);
$stmt->bindParam(':start', $_POST['newStart']);
$stmt->bindParam(':end', $_POST['newEnd']);
$stmt->execute();

$response = new Result();
$response->result = 'OK';
$response->message = 'Update successful';

header('Content-Type: application/json');
echo json_encode($response);

我不明白,因为我只更新新的开始和结束日期。有任何想法吗?感谢

0 个答案:

没有答案