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 7710183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:03:34+00:00 2026-06-01T01:03:34+00:00

The title might not explain my problem fully but I wasn’t sure how to

  • 0

The title might not explain my problem fully but I wasn’t sure how to in a title so I will explain more here.

I have a table which holds various information on bands/acts and I have a browse page which shows all the acts in a certain area etc. Each act can say whether they want drinks/food/accommodation/extra/travel to be paid for. On the browse page I also have a sort function which I want to be able to sort the results by which acts want what paid.

There are five check boxes for each of the options but when I check only travel for example, acts which have travel as well as the others ticked are on top when I want acts which only want travel to be paid for on top.

Currently the sort function starts with the original query from when browsing:

SELECT * FROM acts

And then the sort function appends the ORDER BY statement depending on what has been checked:

SELECT * FROM acts ORDER BY travel DESC

Or if more than one was selected:

SELECT * FROM acts ORDER BY travel DESC, food DESC

But as I said this doesn’t order the list properly (so for the second order by query I’d want an act which only wanted travel and food at the top).

I’ve also tried adding in ORDER BY ASC for the options which weren’t selected but this didn’t help.

Also the columns in the database hold either “yes” or “no” which is why I’ve used DESC when I want them to be on top. I didn’t make the database and it can’t be changed either.

Thanks for any help.

EDIT: you can see what I mean here: http://www.acthook.com/browse.php If you leave the browse boxes blank and click browse to get all results, then tick travel and click sort, there is an act wanting only travel part way down the first page.

  • 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-01T01:03:36+00:00Added an answer on June 1, 2026 at 1:03 am

    Oh I see, thanks for the example, it wasn’t that clear without 🙂
    Then you should have something like this:

    SELECT * FROM acts ORDER BY travel DESC, food ASC, accomodation ASC, drink ASC, extra_fee ASC;
    

    And if the user clicks on food too:

    SELECT * FROM acts ORDER BY travel DESC, food ASC, accomodation ASC, drink ASC, extra_fee ASC;
    

    Or if he clicks only on food:

    SELECT * FROM acts ORDER BY food DESC, travel ASC, accomodation ASC, drink ASC, extra_fee ASC;
    

    As you can see here, the order of the fields in the order clause have been changed. You’ll have to pay attention to that too.

    In order to build the query, you can do something like this :

    $allowedOrderBy = array('travel','food','dring','extra_fee');//etc
    $foundOrderBy = array();
    foreach ($_POST as $orderBy) {
        if (in_array($orderBy, $allowedOrderBy)) {
             $foundOrderBy[] = $orderBy;
        }
    }
    $notFoundOrderBy = array_diff($allowedOrderBy, $foundOrderBy);
    $orderByStr = implode(' DESC,', $foundOrderBy).' DESC, ';
    $orderByStr.= implode(' ASC,', $notFoundOrderBy). 'ASC';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title might not be clear, but I'll explain it here. I'm a total
the title might be a little bit confusing, let me explain, ;) I have
The title is not clear so let me explain: In my apps, I have
The title might not be clear, but I don't know how else to put
I understand that the title might not be descriptive enough, but I'm making a
the title might be too generic, but I have a very specific question about
The title might not be easy to understand but it seems to me it
I have heard it might not be made for this, but I'd really like
Title might be a bit confusing, so let me explain. I have a website
the title might not explain my need well. Basically, beginning of the page, I

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.