I have a very small script to get all records from a database table, the code is below
$query = $this->db->get($this->table_name);
return $query->result();
using this syntax, how would i ORDER BY 'name' ?
I get errors everytime i stick the order by bit on the end.
Cheers,
I believe the get() function immediately runs the selection query and does not accept ORDER BY conditions as parameters. I think you'll need to separately declare the conditions, then run the query. Give this a try.
$this->db->from($this->table_name);
$this->db->order_by("name", "asc");
$query = $this->db->get();
return $query->result();
Using this code to multiple order by in single query.
$this->db->from($this->table_name);
$this->db->order_by("column1 asc,column2 desc");
$query = $this->db->get();
return $query->result();
Simple and easy:
$this->db->order_by("name", "asc");
$query = $this->db->get($this->table_name);
return $query->result();
Just add the'order_by' clause to your code and modify it to look just like the one below.
$this->db->order_by('name', 'asc');
$this->db->where('table_name');
There you go.
Try This:
$this->db->select('main.*');
$this->db->from("ci_table main");
$this->db->order_by("main.id", "DESC");
return $this->db->get()->result();
100% Working!!!!
$this->db->order_by('price', 'ASC');
$q=$this->db->get('add_new_car');
return $q->result_array();
Use order_by
:
$this->db->order_by("coloumn_name", "desc");
$query = $this->db->get('table_name');
return $query->result();