Note that there are some explanatory texts on larger screens.

plurals
  1. POhaving a hard time putting sort on my website sor links that would give chosen sorted fields
    text
    copied!<p>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 </p> <pre><code> &lt;table&gt; &lt;tr&gt; &lt;th&gt; &lt;a href="?orderBy=date"&gt;Type:&lt;/a&gt; &lt;/th&gt; &lt;th&gt; &lt;a href="?orderBy=FirstName"&gt;Description:&lt;/a&gt; &lt;/th&gt; &lt;th&gt; &lt;a href="?orderBy=Lastname"&gt;Recorded Date:&lt;/a&gt; &lt;/th&gt; &lt;th&gt; &lt;a href="?orderBy=Date"&gt;Added Date:&lt;/a&gt; &lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?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); </code></pre> <p>sort don't work outputs nothing example <code>public_search.php?orderBy=FirstName</code></p> <p>update when i use the query of :</p> <p><code>select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' ORDER BY status DESC LIMIT $start,$per_page</code> </p> <p>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</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload