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.
我只想这样做,这样,当用户对检查箱进行检查时,检查箱的分类成本最低,最昂贵。 我做了哪些错误?
注:购买是指每行的价格数据存放在哪里。
<><><><>>><>>>>><>>>>>>
<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