Sorting Results
Posted: Thu Oct 21, 2004 9:16 am
does anyone know of a way of using hyperlinks to sort the results of a query?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<a href = 'this_page.php?sort=age'>Age</a>Code: Select all
$query = "SELECT * FROM blah";
if(isset($_GET['sort'])){
if($_GET['sort']=='title'){
$query .= " ORDER BY title";
}else{
$query .= " ORDER BY id";
}
}Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
ok i did it and now its giving me the following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc LIMIT 0, 10' at line 1
here is my code:Code: Select all
$query_Recordset1 = "SELECT * FROM `data`";
if (isset($_GET['sort'])) {
if($_GET['sort'] =='id') {
$query_Recordset1 .= " ORDER BY id asc";
}else {
$query_Recordset1 .= " ORDER BY beds asc";
}
}
if (isset($_GET['sort2'])) {
if($_GET['sort2'] =='id') {
$query_Recordset1 .= " ORDER BY id asc desc";
}else {
$query_Recordset1 .= " ORDER BY beds desc";
}
}
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]