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

  • Home
  • SEARCH
  • 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 7793431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:29:12+00:00 2026-06-01T22:29:12+00:00

I’m querying a table in a db using php. one of the fields is

  • 0

I’m querying a table in a db using php. one of the fields is a column called “rank” and has data like the following:

none
1-bronze
2-silver
3-gold
...
10-ambassador
11-president

I want to be able to sort the results based on that “rank” column. any results where the field is “none” get excluded, so those don’t factor in. As you can already guess, right now the results are coming back like this:

1-bronze
10-ambassador
11-president
2-silver
3-gold

Of course, I would like for it to be sorted so it is like the following:

1-bronze
2-silver
3-gold
...
10-ambassador
11-president

Right now the query is being returned as an object. I’ve tried different sort options like natsort, sort, array_multisort but haven’t got it to work the way I’m sure it can. I would prefer keeping the results in an object form if possible. I’m passing the data on to a view in the next step. although, it’s perfectly acceptable to pass the object to the view and then do the work there. so it’s not an issue after all. 🙂

thank you for your help. i’m hoping I’m making sense.

  • 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-06-01T22:29:13+00:00Added an answer on June 1, 2026 at 10:29 pm

    How about using this function to sort. I assume if you are getting an object you should convert object to array then use this

    function arraySubSort($array, $subkey, $sort = 'asort') 
    {
      foreach($array as $key => $value) 
      {
        $temp[$key] = strtolower($value[$subkey]);
      }
    
      $sort($temp);
      foreach($temp as $key => $value) 
      {
        $result[] = $array[$key];
      }
      return $result;
    }
    
    $data = $your_array;
    $field = 'ranks';
    arraySubSort($data,$field);
    

    It will sort the array with the field you assign. If you are getting multiple records its a good thing to use to sort.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.