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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:24:22+00:00 2026-05-30T01:24:22+00:00

I have a simple list-type php page, which lists items according to a mysql

  • 0

I have a simple list-type php page, which lists items according to a mysql query, like:

mysql_select_db($database_connBHN, $connBHN);
$query_rsMarket = "SELECT * FROM my_items WHERE active=1 ORDER BY name asc";
$rsMarket = mysql_query($query_rsMarket, $connBHN) or die(mysql_error());
$row_rsMarket = mysql_fetch_assoc($rsMarket);
$totalRows_rsMarket = mysql_num_rows($rsMarket);

then the page list these items and their description in separate tables.

Initially this page lists these items in alphabetical order. Now I would like to put a drop down box on the top of the page, where the user could choose another two or three more sorting options, like date, or itemId, etc, which values are stored in the database.

How could I solve this in a simple way, without leaving that page? (i.e. I do not want to create separate pages for each different result set)

  • 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-30T01:24:25+00:00Added an answer on May 30, 2026 at 1:24 am

    No, it’s easier to keep this as a single script and just allow for the sorting variable to be switched. For security’s sake, it’s best to limit the user input to a per-defined set of options in the PHP script:

    $sort_options = array('name asc','name desc','dateadded asc','dateadded desc');
    if(!isset($_GET['field'])){
       $_GET['field'] = 'name';
    }
    if (!isset($_GET['order'])){
       $_GET['order'] = 'asc';
    }
    
    $full_query_sort = $_GET['field'].' '.$_GET['order'];
    if (!in_array($full_query_sort,$sort_options)){
       die('invalid selection');
    }
    
    mysql_select_db($database_connBHN, $connBHN);
    $query_rsMarket = "SELECT * FROM my_items WHERE active=1 ORDER BY ".$full_query_sort;
    $rsMarket = mysql_query($query_rsMarket, $connBHN) or die(mysql_error());
    $row_rsMarket = mysql_fetch_assoc($rsMarket);
    $totalRows_rsMarket = mysql_num_rows($rsMarket);
    

    Now you can just have the order set with _GET variables: http://example.com/page.php?field=name&order=desc etc. This can be set with javascript (or on form submission) using dropdowns:

    <select id='field_select' 
       name='field' 
       onchange="window.location='?field='+this.value+'&order='+document.getElementById('order_select').value;">
          <option value='name' <?php if(!isset($_GET['field']) || $_GET['field']=='name'){echo "selected";} ?>>Sort by Name</option>
          <option value='dateadded' <?php if(isset($_GET['field']) && $_GET['field']=='dateadded'){echo "selected";} ?>>Sort by Date Added</option>
    </select>
    
    <select id='order_select' 
       name='order' 
       onchange="window.location='?field='+document.getElementById('field_select').value+'&order='+this.value;">
          <option value='asc' <?php if(!isset($_GET['order']) || $_GET['order']=='asc'){echo "selected";} ?>>Ascending/option>
          <option value='desc' <?php if(isset($_GET['order']) && $_GET['order']=='desc'){echo "selected";} ?>>Decending</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple accordion type page containing a list of H3 headers and
I have a simple html form. On php page. A simple list is placed
I have a simple list like this: <ul id=cyclelist> <li>Item 1</li> <li>Item 2</li> <li>Item
I have a simple list of strings, which may be of arbitrary length. I'd
I have a simple unordered list with list items as menu item i created
I have a simple MySQL table thats contains a list of categories, level is
I have a simple task list which contains amongst others a title field and
I have a simple list I am using for a horizontal menu: <ul> <h1>Menu</h1>
I have a simple list view with some check boxes in an alert dialog.
I have a simple ul list. the li's contain simple a href's. I have

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.