daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Nov 19th, 2017 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. +----------+----------------------------------+
  2. | class_id | name                             |
  3. +----------+----------------------------------+
  4. | BBI2424  | Academic Writing                 |
  5. | MTH3100  | Calculus                         |
  6. | SIM4207  | Ethics In Computing              |
  7. | SSE3304  | Software Design                  |
  8. | SSK3118  | Data Structure and Algorithm     |
  9. | SSK3408  | Database Application Development |
  10. +----------+----------------------------------+
  11.    
  12. +----------+----------+------------+----------+---------+
  13. | class_id | day      | start_time | end_time | type    |
  14. +----------+----------+------------+----------+---------+
  15. | MTH3100  | Tuesday  | 10:00:00   | 12:00:00 | lecture |
  16. | MTH3100  | Thursday | 11:00:00   | 12:00:00 | lecture |
  17. +----------+----------+------------+----------+---------+
  18.    
  19. public function beforeFilter()
  20. {
  21.     // load classes model alias as classes
  22.     $this->load->model('classes_model', 'classes');
  23.     $this->load->model('schedules_model','schedules');
  24. }
  25.  
  26. /**
  27.  * index
  28.  *
  29.  * listing data classes
  30.  *
  31.  * @access public
  32.  * @return void
  33.  */
  34. public function index()
  35. {  
  36.     // get data from database
  37.     $content['classes'] = $this->classes->lists();
  38.  
  39.     // capture classes content to template
  40.     $data['content'] = $this->view->fetch('classes/list', $content);
  41.  
  42.     // bind content to template
  43.     $this->view->display('example_layout', $data);
  44. }
  45.    
  46. public function lists()
  47. {
  48.     // get all data from table classes
  49.     $this->db->join('schedules','schedules.class_id=classes.class_id');
  50.     return $this->db->find_all('classes');
  51. }
  52.    
  53. public function create()
  54. {  
  55.     // load input library
  56.     $this->load->library('input');
  57.     $content['classes']=$this->classes->lists();
  58.  
  59.     // get input data & filter it
  60.     $input = $this->input->post('data', true);
  61.  
  62.     // input data exist
  63.     if ( $input !== false )
  64.     {
  65.         // insert new data to database
  66.         if ( $this->schedules->create($input) )
  67.             redirect('/schedules/index');
  68.     }
  69.  
  70.     // capture form
  71.     $data['content'] = $this->view->fetch('schedules/create',$content);
  72.  
  73.     // bind content to template
  74.     $this->view->display('example_layout', $data);      
  75. }
  76.    
  77. public function create($input)  
  78. {
  79.  
  80.     // insert new data to table schedules
  81.     return $this->db->insert('schedules', $input);
  82. }
  83.    
  84. <form role="form" action="<?php echo CONF_BASE_PATH; ?>/schedules/create" method="post">
  85. <div class="form-group">
  86. <label for="data[class_id]">Class Id:</label>
  87. <select class="form-control" name="data[class_id]">
  88.     <?php foreach($classes as $class){ //this line code return class_id from Schedules instead. i want to return from Classes ?>
  89.         <option value="<?php echo $class['class_id'] ?>"><?php echo $class['class_id'] ?></option>
  90.     <?php } ?>
  91. </select>
  92. </div>
RAW Paste Data
Top