[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>
<?php echo form_submit('submit','Submit'); ?>
</div>
<!-- End Sort -->
<?php echo form_close();?>
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:
<?php if (isset($backlinks)) : foreach ($backlinks as $row) : ?>
<?php echo $row->name; ?>
<?php endforeach; ?>
<?php endif; ?>
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