[英]WHERE in groceryCRUD
I have problem and I am requesting for your help.我有问题,我请求您的帮助。
I am trying to use WHERE depending on user inputs;我正在尝试根据用户输入使用 WHERE; I would like if there is no user inputs system should take default settings from the db but if there is user inputs the system should use it;
我想如果没有用户输入系统应该从数据库中获取默认设置但是如果有用户输入系统应该使用它; I have the following codes but do not work!
我有以下代码但不起作用! Please help me;
请帮我; thanks.
谢谢。
public function show_list()
{
//Page title
$data['page_title'] = 'Users List';
if( $this->require_min_level(1) ){
//if there is inputs data for custom selection do this
$testdate1=$this->input->post('start_date');
$testdate2=$this->input->post('end_date');
if($testdate1=="" && $testdate2=="")
{
// this load system data in order to use it in querying the db
$system_data=$this->system_data_model->load_system_data();
foreach ($system_data->result() as $sdata){
$data['financial_year_start'] = $sdata->financial_year_start;
$data['financial_year_end'] = $sdata->financial_year_end;
}
}
//if there is inputs data for custom selection do this
else{
$data = array(
'financial_year_start' => $this->input->post('start_date'),
'financial_year_end' => $this->input->post('end_date'),
'custom_financial_year_end'=>$this->input->post('end_date'),
);
}
$crud = new grocery_CRUD();
$crud->where('employed_date>=', $data['financial_year_start']);
$crud->where('employed_date<=', $data['financial_year_end']);
$crud->set_table('users');
$crud->columns('user_id', 'first_name', 'last_name','gender','user_name','mobile_number','user_email','company_division','job_position', 'office_location', 'employed_date');
$crud->fields('user_id', 'first_name', 'last_name','gender','user_name','mobile_number','user_email','company_division','job_position', 'office_location', 'employed_date');
// edit how column data is displayed
$crud->display_as('company_division','Division');
$crud->display_as('job_position','Position');
$crud->display_as('employed_date', 'Employed');
//prevent unwanted operations
$crud->unset_read();
$crud->unset_add();
$crud->unset_delete();
$crud->unset_edit();
//render data
$output = $crud->render();
//call aotput function
$this->_users_list_output($data, $output);
}
}
function _users_list_output($data, $output = null)
{
if( $this->require_min_level(1) ){
//load view
$this->load->view('includes/header', $data);
$this->load->view('includes/reports_menu');
$this->load->view('list_users_view',$output);
$this->load->view('includes/footer');
}
}
}
public function show_list()
{
$data = array(
'list_item' => $this->input->post('name')
);
if($this->input->post('name') == ""){//assuming empty is passed, you can also check to see if it's set
$this->db->where('default_settings');
}else{
$this->db->where('name', $this->input->post('name');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.