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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:07:36+00:00 2026-05-30T05:07:36+00:00

I am stuck with this, I have been putting myself through a crash course

  • 0

I am stuck with this, I have been putting myself through a crash course in PHP all week making a fake amazon like site! I want to order my table using a drop down menu but cant work out how! I know the SQL thats the easy bit but the way I have tried to do it is follows:

Set up variables for example

$query = "SELECT bookname, bookauthor, bookpub, bookisbn
                FROM booktable
                ORDER BY bookname ASC";

$query2 = "SELECT bookname, bookauthor, bookpub, bookisbn
            FROM booktable
            ORDER BY bookauthor ASC";

Then I have my form=

<form name="sort" action="products.php" method="post">
<select name="order">
   <option value="choose">Make A Selection</option>
   <option value="title">Title</option>
   <option value="author">Author</option>
   <option value="publisher">Publisher</option>
   <option value="isbn">Book ISBN-10</option>
</select>
<input type="submit" value=" - Sort - " />
</form>

Now for the bit I cant do,

I set up the variable:

$sort = $_POST['order']; 

so that whatever the value of the dropdown menu is, will become assigned to the variable $sort….. (is that right?)

then I want to say IF the value of $sort is the same as lets say ‘author’ than $query = $query2
but I dont know how to say it without huge error courtesy of XAMPP!

I hope this all makes sense and that my method to try and achieve it is close to correct

Thank you

  • 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-30T05:07:37+00:00Added an answer on May 30, 2026 at 5:07 am

    To sort I would do the following:

    Change the option values to match the column names from your table
    Set your sort option including a default if they haven’t selected anything:

    $sort=$_POST["order"]!="choose"?$_POST["order"]:"bookname";
    

    then simply set your query to use:

    ORDER BY ".mysql_real_escape_string($sort)." ASC
    

    This way you only need one query, rather than a query for each case.

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

Sidebar

Related Questions

I'm stuck on this and have been all day.. I'm still pretty new to
I have been stuck on this all weekend and failed miserably! Please help me
so i have been stuck with this issue for 3 weeks now and i
I have been stuck on this for a while now and I cannot seem
I have been stuck on this for days, and was wondering if anyone had
I have been stuck on this for a while. i have tried and I
I have been stuck on this and don't really know how to go about
I have been stuck on this silly if statement, whatever i do, I cannot
I have now been stuck at this for some time so I though to
I have been working on this for few hours and got stuck, so how

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.