can anyone help me with my sort by? nothing happens when clicking the sort no errors tried the codes 4 years ago don't know if it's still usable the sql.= i think don't work or my other query just disables it. here's my sql command thanks :D. help with the order by
<table>
<tr>
<th>
<a href="?orderBy=date">Type:</a>
</th>
<th>
<a href="?orderBy=FirstName">Description:</a>
</th>
<th>
<a href="?orderBy=Lastname">Recorded Date:</a>
</th>
<th>
<a href="?orderBy=Date">Added Date:</a>
</th>
</tr>
</table>
<?php
$sort=$_GET['orderBy'];
$searchtext = '';
if(isset($_GET['q']))
$searchtext = mysql_real_escape_string($_GET['q']);
if($searchtext) {
$per_page =5;
$pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' order by '$sort' desc ");
$pages = ceil(mysql_result($pages_query,0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] ;
$start = ($page - 1) * $per_page;
// And set the first page $first_page = "1";
$num = mysql_num_rows($pages_query);
$last_page = ($num / $per_page);
$next_page = $page + 1;
$last_page=$pages;
$query=mysql_query("select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' order by '$sort' desc LIMIT $start,$per_page ");
$count=mysql_query("select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%'");
$numrows = mysql_num_rows($count);
}
else {
$per_page =5;
$pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons ");
$pages = ceil(mysql_result($pages_query,0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$last_page=$pages;
// And set the first page $first_page = "1";
$query=mysql_query("select * from persons order by '$sort' desc LIMIT $start,$per_page "); $count=mysql_query("select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' order by '$sort'");
$numrows = mysql_num_rows($count);
sort don't work outputs nothing example public_search.php?orderBy=FirstName
update when i use the query of :
select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' ORDER BY status DESC LIMIT $start,$per_page
it works so i conclude that it don't get the sort command sql won't get the value of sort tried to echo it and worked. it outputs the sort but the query won't execute it