php - CakePHP display all data between 2 dates -


i new cakephp. i'm having task self-learning want display data phpmyadmin between 2 selected dates when user click 'show' , display @ same page "index.ctp".

however, i'm stuck know should put codes can display information. below codes had done till now:


model (room.php):

<?php class room extends appmodel{     public  $validate = array(          'sdate' => array(             'date' => array(                 //add 'ymd' rule.                 'rule' => array('date', 'ymd'),                 'message' => 'please select valid start date.',             ),         ),     );         'edate' => array(             'date' => array(                 //add 'ymd' rule.                 'rule' => array('date', 'ymd'),                 'message' => 'please select valid end date.',             ),         ),     ); } 

controller (roomcontroller.php):

    <?php     class roomscontroller extends appcontroller{         public $helpers = array('html', 'form');         public $components = array('session');          public function index() {          }      } ?> 

index.ctp

    <h1>room reservation<h1>  <table>     <?php         echo $this->form->create('rooms',              array(                 'type' => 'get'             )         );         echo $this->form->input('start date:',             array(                 'label' => 'start date',                  'id' => 'sdate'             )         );         echo $this->form->input('end date:',             array(                 'label' => 'end date',                  'id' => 'edate'             )         );         echo $this->form->end('show');     ?> </table>  <script type="text/javascript">     $(document).ready(function() {         $('#sdate').zebra_datepicker();         $('#edate').zebra_datepicker();     }); </script> 

room_type(database):

create table `room_type` ( `room_id` int(11) not null auto_increment, `room_type` varchar(10) not null, `no_of_room` int(10) not null, primary key (`room_id`) );  room_id | room_type | no_of_room     1   |         |    10     2   |     b     |    10     3   |     c     |    10     4   |     d     |    10 

room_type_availability(database):

create table `room_type_availability` ( `id` int(11) not null auto_increment, `room_id` int(11) not null, `trx_date` date not null, `no_of_room` int(2) not null, primary key (`id`), add key `room_id` (`room_id`), constraint `room_type_availability_ibfk_1` foreign key (`room_id`) references `room_type` (`room_id`) on delete cascade on update cascade );      id | room_id | trx_date  | no_of_room     1  |     1   |2015-05-05 |    10     2  |     1   |2015-05-06 |    10     3  |     1   |2015-05-07 |    9     4  |     1   |2015-05-08 |    7     5  |     1   |2015-05-09 |    6     6  |     2   |2015-05-05 |    8     7  |     2   |2015-05-06 |    3     8  |     2   |2015-05-07 |    6     9  |     2   |2015-05-08 |    4    10  |     2   |2015-05-09 |    5 

if date selected in database, display room_type_availability database.

else if date selected not in database, display room_type database.

hope guys can give advice on it.

thanks helping , appreciate it.

:)

//in controller  public function index() {      if($this->request->ispost()) {         $obj = $this->loadmodel('roomtypeavailability');         $start_date = $this->request->data['sdate'];         $end_date  = $this->request->data['edate'];         // use "between" range         $conditions = array('roomtypeavailability.trx_date between ? , ?' => array($start_date, $end_date));         $data = $this->roomtypeavailability->find('all',array('conditions'=>$conditions));          $this->set('data', $data);     }   } 

in room model

class room extends appmodel{  public $usetable = false;  public  $validate = array(      'sdate' => array(         'date' => array(             //add 'ymd' rule.             'rule' => array('date', 'ymd'),             'message' => 'please select valid start date.',         ),     ), );     'edate' => array(         'date' => array(             //add 'ymd' rule.             'rule' => array('date', 'ymd'),             'message' => 'please select valid end date.',         ),     ), ); } 

in roomtype model

class roomtypeavailability extends appmodel {      public $usetable = 'room_type_availability';      public $validate = array( ); } 

// index.ctp

<h1>room reservation<h1>  <table>     <?php         echo $this->form->create('rooms',              array(                 'type' => 'post'             )         );         echo $this->form->input('start date:',             array(                 'label' => 'start date',                  'id' => 'sdate',                 'name' => 'sdate'             )         );         echo $this->form->input('end date:',             array(                 'label' => 'end date',                  'id' => 'edate',                 'name' => 'edate'             )         );         echo $this->form->end('show');     ?> </table> <?php if(isset($data) && count($data)>0) { ?> <table>     <tr>         <th>id</th>         <th>room_type</th>         <th>trx_date</th>         <th>no_of_date</th>     </tr>      <?php foreach($data $row) { ?>         <tr>             <td><?php echo $row['roomtypeavailability']['id']?></td>             <td><?php echo $row['roomtypeavailability']['room_type']?></td>             <td><?php echo $row['roomtypeavailability']['trx_date']?></td>             <td><?php echo $row['roomtypeavailability']['no_of_date']?></td>         </tr>     <?php } ?>  </table> <?php } ?> <script type="text/javascript">     $(document).ready(function() {         $('#sdate').zebra_datepicker();         $('#edate').zebra_datepicker();     }); </script> 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -