HTML
1<input type="checkbox" name="name[]" value="hoge01"> 2<input type="checkbox" name="name[]" value="hoge02"> 3<input type="checkbox" name="name[]" value="hoge03">
PHP
1//HogesController.php 2if($this->request->is('post')){ 3 $value = $this->request->data('name');//チェックボックス(配列) 4 $hoges = $this->Hoges->find() 5 ->where(["column1 IN" => $value]); 6 }
$this->request->data('name')
がnull
だった時
->where(["column1 IN" => $value]);
を生成しないようにしたいです。
######理由
->where(["column IN" => $value]);
の$valueがnullだと検索が機能しないからです。
######補足
他にも複数チェックボックスの項目があります。
->where(["column IN" => $value]);
を動的に生成する方法が良いとは思うのですが、
皆さんはチェックボックスのデータベース検索はどうされていますか?
PHP
1//HogesController.php 2if($this->request->is('post')){ 3 $value = $this->request->data('name');//チェックボックス(配列) 4 $hoges = $this->Hoges->find() 5 ->where(["column1 IN" => $value]); 6 ->where(["column2 IN" => $value2]); 7 ->where(["column3 IN" => $value3]); 8 }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/25 07:21
2017/01/25 07:40
2017/01/25 07:55
2017/01/25 08:28
2017/01/25 08:31
2017/01/26 08:33
2017/01/26 12:22 編集
2017/01/26 13:25