Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:57:16+00:00 2026-05-31T00:57:16+00:00

How do we sort using the database class in expressionengine. orderby and sort are

  • 0

How do we sort using the database class in expressionengine. orderby and sort are given an error and do not seem to work. I can’t seem to find anything in the documantation about sorting results. This is what i have.

$results = $this->EE->db->query("
    SELECT plan_name
    FROM exp__plans 
    WHERE member_id='1002' AND orderby="id" sort="desc" LIMIT 1
");
$x = $results->row('plan_name')

;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:57:18+00:00Added an answer on May 31, 2026 at 12:57 am

    There are issues with your query.

    try:

    $results = $this->EE->db->query("
        SELECT plan_name
        FROM exp_plans
        WHERE member_id = '1002' 
        ORDER BY id DESC LIMIT 1 
    ");
    

    I would recommend trying to run your query directly against the database if you’re having trouble with it. 90% of the time it will be an issue with your SQL.

    Also, you are writing this in a add-on… right? if you’re trying to get this to work within a template I would recommend checking out the query module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using LINQ to SQL to pull records from a database, sort them by
How can I do a multi-level parent-child sort using Linq if I have a
Is there a better way to shell sort using C#? // array of integers
I have an array that I would like to sort using a date field
I've a code to sort table using Jquery.I use toggle function to alternate clicks,and
The other day I saw a colleague of mine using sort to sort a
When I sort an Array using the native sort method, which algorithm does Ruby
I am trying to sort a list using delegates but I am getting a
Is there some library for using some sort of cursor over a file? I
i have one problem when i sort the NSMutablearray using date and time wise.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.