Welcome Guest, Not a member yet? Register   Sign In
Sorting not working for dynamic values.
#1

Hello everybody,

I'll get right to it.

I am trying to a sort user list by either desc or asc.

My controller looks like this -
PHP Code:
public function ByUser($sort_by 'issue_date'$sort_order 'desc')
    {
        
/**
         * Store _POST value from dropdown in variable - $user_type.
         * Pass that value to model to get issues only "by that user"
         */
        
$user_type $this->input->post('issues-by-user');
        
        
$data['records'] =  $this->report_model->issues_by_user($sort_by$sort_order$user_type);
        
        
$data['main_content'] = 'report';
        
$data['title'] = 'MarksMate Report';
        
$this->load->view('includes/template'$data);
    } 

In my model, i have an inner join that joins two tables and shows issues by specific user.

My model method looks like this -
PHP Code:
public function issues_by_user($sort_by$sort_order$user_type)
    {
        
$sort_order = ($sort_order == 'asc') ? 'asc' 'desc';
        
$sort_columns = array('id''issue_date');
        
$sort_by = (in_array($sort_by$sort_columns)) ? $sort_by 'issue_date';

        
$query $this->db->select('tblissue.id, student_id, issue_date, issue_title, issue_description, issue_screenshot, first_name, last_name, email_id, role')
                        ->
from('tblissue')
                        ->
join('tblstudentprofile''tblissue.student_id=tblstudentprofile.id')
                        ->
where('role'$user_type)
                        ->
order_by($sort_by$sort_order);

        
$records $query->get()->result_array();
        
        return 
$records;
    } 

Query works fine. (Checked it using print_r)

But when i change the url to - "http://localhost/anothertrack/report/ByUser/id/asc", all the records that were fetched go away. If i print_r, all i see is an empty array.

However, if i remove the variable
PHP Code:
$user_type 
from
PHP Code:
->where('role'$user_type
and instead put a constant value like 0 or 1 or 2 (0,1,2,3 are my enum values set in database) then it works.

Where am i going wrong here?
Reply


Messages In This Thread
Sorting not working for dynamic values. - by prasad - 10-16-2015, 10:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB