CodeIgniter Forums
Basic sorting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Basic sorting (/showthread.php?tid=45409)



Basic sorting - El Forum - 09-20-2011

[eluser]Michal1[/eluser]
Hi guys,

I am trying to sort my data by a function in parameters but it does not work allright. I basically have a dropdown in view and I want to take selected value, pass it into function and use it in where clause in model to get data if it is matched. It sounds kinda complicated but I think you will get what I want once you see a code.

So in my site_view I have

Code:
<?php echo form_open('site/order'); ?>
                        <!-- Sort -->
                        <div class="sort">
                            <label>Sort by</label>
                            <select name="picker" class="field">
                                <option  value="mount">mount</option>
                            </select>
                            
                            &lt;?php echo form_submit('submit','Submit'); ?&gt;
                            
                        </div>
                        &lt;!-- End Sort --&gt;
                        
                        &lt;?php echo form_close();?&gt;

Then in controller site I have a functin order and inside

Code:
public function order()
        {
         $data = array();
          $data['backlinks']=$this->site_model->get_order($this->input->post('picker'));
        
        
         $this->load->view('order_view',$data);
        }

In order_view I of course display data like

Code:
&lt;?php if (isset($backlinks)) : foreach ($backlinks as $row) : ?&gt;

&lt;?php echo $row->name; ?&gt;

&lt;?php endforeach; ?&gt;
&lt;?php endif; ?&gt;

And then in site_model I have a
Code:
function get_order($parameter)
{
$this->db->where('type',$parameter);
$query = $this->db->get('data');

return $query->result();
}
So basically it should just take only data from database where the "type" field is equal to $parameter which in this case is 'mount'. But my script then echos all data(records) in order_view and I dont know why. Is there something I am missing? I bet it will be some stupid mistake. Thank you Smile