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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:28:07+00:00 2026-06-13T10:28:07+00:00

I’m trying to sort a PHP generated form by price. I get an error

  • 0

I’m trying to sort a PHP generated form by price. I get an error message ‘Notice: Undefined index: PriceDesc/Asc’. I understand the error message but can’t find any relevant info through searching so thought I’d ask. I’m new to PHP and so far this is the code I have:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <!--[if IE]>
  <link href="blueprint/ie.css" type="text/css" rel="stylesheet">
  <![endif]-->
  <link href="blueprint/screen.css" type="text/css" rel="stylesheet">
  <link href="style.css" type="text/css" rel="stylesheet">

  <title>Enygma Peripherals</title>
</head>

<body>
<div id="wrapper" class="container">
    <div id="top" class="span-24">
        <div id="logo" class="span-5">
            <a href="index.php"><img src="images/logo.png" alt="Enygma"></a>
        </div>
        <div id="nav" class="span-11 last">
            <ul>
                <li><a href="index.php">HOME</a></li>
                <li><a href="products.php">PRODUCTS</a></li>
                <li><a href="about.php">ABOUT</a></li>
                <li><a href="contact.php">CONTACT</a></li>
            </ul>
        </div>

    </div>
    <div id="mainContent" class="span-24">
        <h2>Products</h2>
        <div id="left" class="span-8">
        </div>
        <div id="right" class="span-15 last">
            <form method="get" name="sort">
                <select name="sort" id="sort">
                    <option value="">--Select--</option>
                    <option value='PriceAsc'>Price: Highest First</option>
                    <option value='PriceDesc'>Price: Lowest First</option> 
                </select>
                <input type="submit" value="Sort"/>
            </form>
            <?php
                include("connection.php");

                $data = mysql_query("SELECT * FROM products");
                IF ($_GET['PriceAsc']){
                    $orderby=" ORDER BY price ASC";
                } 
                IF ($_GET['PriceDesc']){
                    $orderby=" ORDER BY price DESC";
                }
                Print "<table border cellpadding=10>"; 
                while($info = mysql_fetch_array( $data )) 
                { 
                Print "<tr>"; 
                Print "<th>Product Number:</th> <td>".$info['product_no'] . "</td> "; 
                Print "<th>Product:</th> <td>".$info['product_name'] . "</td> "; 
                Print "<th>Type:</th> <td>".$info['type'] . "</td> "; 
                Print "<th>Price:</th> <td>".$info['price'] . "</td> "; 
                Print "<th>Availability:</th> <td>".$info['availability'] . " </td></tr>"; 
                } 
                Print "</table>"; 
                ?>
        </div>      
    </div>
    <div id="footer" class="span-24">
        <a href="acknowledgements.html">Acknowledgments</a>
    </div>
</div>

For the record, I’m using PhpMyAdmin for my backend d/b and the initial tabled data works fine.

  • 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-13T10:28:08+00:00Added an answer on June 13, 2026 at 10:28 am

    Replace

    $data = mysql_query("SELECT * FROM products");
                IF ($_GET['PriceAsc']){
                    $orderby =" ORDER BY price ASC";
                } 
                IF ($_GET['PriceDesc']){
                    $orderby =" ORDER BY price DESC";
                }
    

    with

    if ( !empty($_GET['sort']) && $_GET['sort'] == 'PriceAsc' ) {
        $orderby=" ORDER BY price ASC";
    } 
    if ( !empty($_GET['sort']) && $_GET['sort'] == 'PriceDesc' ) {
        $orderby=" ORDER BY price DESC";
    }
    
    $data = mysql_query("SELECT * FROM products".$orderby);
    

    Note the changes, you need to use empty() to check if form submitted and check the value of it. And do the query once Order by appended to SQL.

    • 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&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.