Welcome Guest, Not a member yet? Register   Sign In
active record database query using order_by
#1

[eluser]blasto333[/eluser]
This Works
Code:
$modules=array();
$query = $this->db->query('SELECT * FROM modules ORDER BY `sort` asc');

foreach($query->result() as $row)
{
    $modules[]=$row->id;
}



This doesn't work (Fatal error: Call to undefined method CI_DB_mysql_driver::result() )
Code:
$modules=array();
$this->db->get('modules');
$query = $this->db->order_by("sort", "asc");

foreach($query->result() as $row)
{
    $modules[]=$row->id;
}
return $modules;

Any ideas? I am using CI 1.6.3
#2

[eluser]xwero[/eluser]
The sql statement building methods have to come before the action method; get, update, insert, ...
Most sql statement building methods have no return.

If you want to build the query in the order of the sql statement than you have to write
Code:
$this->db->from('modules');
$this->db->order_by("sort", "asc");
$query = $this->db->get();
#3

[eluser]blasto333[/eluser]
Ah, ok thanks!




Theme © iAndrew 2016 - Forum software by © MyBB