Jump to content
Larry Ullman's Book Forums

Recommended Posts

First I just want to thank Larry for explaining PHP in a method I could understand. From reading his book in three days I went from a barely functioning site with security holes to a improved, stable site. If your interested in seeing it, its here, http://medieval.name


I did have one issue, that is with using a sort feature. I use the template from Chapter 10. Setting the sort variable, setting up the switch, adding $order_by to the query, adding sort to the pagination.


The sort works, but it sorts all data, not limiting itself to the data from the query. Im sure Im missing something obvious. The following is the only editing I did,


// Default is by registration date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'te';

// Determine the sorting order:
switch ($sort) {
    case 'te':
        $order_by = 'term ASC';
    case 'ct':
        $order_by = 'category ASC';
    case 'pl':
        $order_by = 'place ASC';
        $order_by = 'term ASC';
        $sort = 'te';


echo '
    <a href="search_results.php?sort=te">Term</a>
    <a href="search_results.php?sort=ct">Category</a>
    <a href="search_results.php?sort=pl">place</a>


Suggestions are welcome.

Link to comment
Share on other sites

Hi Larry!


Im sorry I wasnt clear. What I mean is, a user can perorm a search using a text box and three drop down lists. For example it could be a seach on Britain in the Dark Ages returning 25 results.


When one of the sort buttons is clickled however, the page is not sorted by the results of Britain in the Dark Ages that returned 25 results. It returns and sorts all of the data in the database, each row, of 725+ results, and is not limiting itself to the user query.



Link to comment
Share on other sites

  • 7 months later...

  • Create New...