Php 检查count()函数中的多行
不确定我是否遗漏了一些简单的东西(我已经为此工作了一段时间)。我正在尝试做一个简单的预约簿,我有一个简单的表格,里面有时间段Php 检查count()函数中的多行,php,mysql,laravel,laravel-4,Php,Mysql,Laravel,Laravel 4,不确定我是否遗漏了一些简单的东西(我已经为此工作了一段时间)。我正在尝试做一个简单的预约簿,我有一个简单的表格,里面有时间段 id timeslot montgomery birmingham 1 8-10 2 2 2 9-12 6 3 3 12-3 6 3 4 3-5 2 2 这是我的控制器 public function getSchedule() { $user = User::f
id timeslot montgomery birmingham
1 8-10 2 2
2 9-12 6 3
3 12-3 6 3
4 3-5 2 2
这是我的控制器
public function getSchedule() {
$user = User::find(Auth::user()->id);
$input = [
'date' => Input::get('date'),
'timeslot' => Input::get('timeslot')
];
$date = strtotime($input['date']);
$dateFormat = date('Y-m-d',$date);
$block = DB::table('bk_timeslot')
->where('id', '=', $input['timeslot'])
->first();
if($user->office == "Birmingham") {
$count = Schedule::where('date', '=', $dateFormat)->count();
$full = "Sorry Birmingham does not have an appointment open for this day";
if ($count >= $block->birmingham) {
return Redirect::to('book/schedule')->withErrors($full)->withInput();
}
}
if($user->office == "Montgomery") {
$count = Schedule::where('date', '=', $dateFormat)
->count();
var_dump($count); die;
$full = "Sorry Montgomery does not have an appointment open for this day";
if ($count >= $block->montgomery) {
return Redirect::to('book/schedule')->withErrors($full)->withInput();
}
}
//puts info in a session for later use
Session::put('schedule', $input);
return Redirect::to('book/review');
}
除了这条线以外,其他所有线路都运行良好:
$count = Schedule::where('date', '=', $dateFormat)->count();
它所做的是计算一整天,而不是检查时间段是否也在占用:
进度表的结构
id date timeslot
1 2013-10-11 1
1 2013-10-11 1
1 2013-10-11 4
因此,如果你试图在10-11预订8-10的时间段,你将无法预订,因为它已满..这很好,但你也无法预订3-5,因为它的id也是2。我怎样才能同时检查这两个选项并从中继续?添加第二个
where
子句:
$count = Schedule::where('date', '=', $dateFormat)
->where('timeslot', '=', $block->id)
->count();
你可以使用
$input['timeslot']
而不是$block->id
(它们应该是相同的)。谢谢你,J。这一定是因为我一直缺乏睡眠来建立这个。哈哈,谢谢你的快速回复!!