Part of the EllisLab Network
   
 
Problem with "orderby"
Posted: 17 April 2006 11:11 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  71
Joined  04-02-2006

I’m having a little problem trying to order my query results.

$this->db->use_table('name_of_table');
$data['query'] = $this->db->get();
$this->db->orderby("id", "desc");

The last line produces the following error message:

Fatal error: Call to undefined method _DB::orderby() in (path.to.CI)\application\controllers\blog.php on line 18

I don’t have a clue as to what I did wrong (again - sigh)
Any ideas?

Profile
 
 
Posted: 17 April 2006 11:20 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRank
Total Posts:  2512
Joined  12-21-2001

Two things:

First of all, this has been deprecated:

$this->db->use_table()

If you check the docs you’ll see there are easier ways to fetch results now.

Second, you are calling “orderby” after you’ve already retrieved your result.  I think a better way would be this:

$this->db->orderby("id", "desc");
$data['query'] = $this->db->get('name_of_table');

Make sure you have connected to your database first.

 Signature 
Profile
MSG
 
 
Posted: 17 April 2006 11:35 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  71
Joined  04-02-2006

Thanks for the reply.
Is it possible I’ll have to upgrade first? The new syntax doesn’t seem to work. I’m just gonna go ahead and do that. Totally missed the new version.
Thanks again.

EDIT: yup, works now

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 119839 Total Logged-in Users: 64
Total Topics: 125973 Total Anonymous Users: 4
Total Replies: 662715 Total Guests: 547
Total Posts: 788688    
Members ( View Memberlist )