Monday, February 25, 2019

CodeIgniter How to make filter function

How to make filter function in PHP.

View

For view, first make the dropdown list and filter button.

<?php echo form_open(''); ?>
<table width="100%">
<tr>
<td align="right">
<?php echo form_dropdown('name', $array_list, $selected_array, 'class="form-control input-inline input-small"'); ?>
<input type="submit" value="<?php echo lang('lbl_filter'); ?>" class="btn btn-primary" />
</td>
</tr>
</table>
<?php echo form_close(); ?>


'name' = data name that will to represent the data and be used to call in controller.
$array_list = data that you want to display inside the dropdown.
$selected_array = array that you have select to filter.



Controller list

$data = array();

      $data['selected_array'] = '';
  
      if ($post = $this->input->post()) {
        $post = $post = $this->input->post();
        $data_name = $post['name']; //data name that hv been set in view
  
        if (!empty($name)) {
          $this->db->where("column in table = $data_name");
          $data['selected_array'] = $data_name;
        }
      }

This controller is used to set the filter function.

No comments:

Post a Comment

IONIC PASS PARAMETER

 To pass parameter to next page, first we need to make sure that we have 2 pages which is page from and page to. In page from ts file, you h...