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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:53:49+00:00 2026-05-27T00:53:49+00:00

I am working on a site which displays products from a database in a

  • 0

I am working on a site which displays products from a database in a listed format, so far so good. However, I would like to add a simple checkbox above which, when ticked, orders the list by price, lowest to highest (and also another one from highest to lowest). I have tried to do this but I’m having problems.

First I added a checkbox (see HTML below) labelled “order by lowest price”. Then I added a line to my php code just below the main database query (about 10 lines down my PHP code), which tries to append a piece of query language on the end of the database query, which is just above, however it doesn’t seem to work.

I just want to make it so that when the user checks the checkbox, it is sorted by cheapest to most expensive. What have I done wrong?

Note: ‘buynow’ is where the price data is stored for each row.

HTML

<form action="spain-holidays.php" method="post">
  <p>Order by lowest price:</p><input name="orderbyprice" type="checkbox" value="orderbyprice" />
</form>

PHP

<?php 

//connect
include ("db.connect.php");

//pagination
$per_page = 20;

$pages_query = mysql_query("SELECT COUNT('id') FROM `holidaytable` WHERE brandname = 'Spain'");
$count = mysql_result($pages_query, 0);
$pages = ceil(mysql_result($pages_query, 0) / $per_page);

$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;

echo '<p>There are '.$count.' holidays<hr></p><br /><br />';

//construct query and insert values

$query = mysql_query("SELECT * FROM holidaytable WHERE brandname = 'Spain' LIMIT $start, $per_page") or die(mysql_error());


//THIS IS THE LINE I ADDED HERE:

if (isset($_POST['orderbyprice'])) $query .= " ORDER BY buynow ASC";



while($rows = mysql_fetch_assoc($query)) {

    $name = $rows['name'];
    $id2 = $rows['id2'];
    $hotelname = $rows['hotelname'];
    $desc = $rows['desc'];
    $spec = $rows['spec'];
    $resort = $rows['resort'];
    $awtrack = $rows['awtrack'];
    $awthumb = $rows['awthumb'];
    $awimage = $rows['awimage'];
    $mthumb = $rows['mThumb'];
    $mlink = $rows['mlink'];
    $mimage = $rows['mimage'];
    $buynow = $rows['buynow'];
    $awcatid = $rows['awcatid'];
    $mcat = $rows['mcat'];
    $brandname = $rows['brandname'];


echo  "<div class='resultbox'>
<div class='resultboxtopbar'>
    <div class='hotelname'><h3>$hotelname</h3></div>
    <div class='price'><h3>From <strong>£$buynow</strong> $spec</h3></div>
</div>
<div class='resultboxmain'>
    <div class='resultboximage'><a href='$awtrack' target='_blank'><img src='$mimage' /></a></div>

        <h4>$resort, $brandname</h4>
        <p>$name</p>
        <p>$desc...</p>
        <div class='moreinfobutton'><input name='moreinfo' type='button' value='moreinfo' /></div>
</div>";

//more pagination, etc
  • 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-27T00:53:50+00:00Added an answer on May 27, 2026 at 12:53 am

    mysql_query() does not return a string and therefore cannot be appended to. You should do something like this instead:

    $sql = "SELECT * FROM holidaytable WHERE brandname = 'Spain' LIMIT $start, $per_page";
    
    if (isset($_POST['orderbyprice'])) $sql .= " ORDER BY buynow ASC";
    
    $query = mysql_query($sql) or die(mysql_error());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple ASP.NET MVC site which displays images from the database.
For the site I'm currently working on, I have a list of products which
I'm currently working on a site which displays map data in Google Maps, but
I'm working on a site which needs to be able to support two or
I'm working on a site which contains a whole bunch of mp3s and images,
I'm working on a site which is at the core/ master of a number
I'm working on a site in which users can opt-in for email notifications for
I have this classic ASP site which has been working fine until we updated
I'm currently working on an intracompany web site which will be viewed on cell
I am working on a URL shortening site which uses PHP, MySQL and Apache.

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.