Beltic Posted February 21, 2014 Share Posted February 21, 2014 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'; break; case 'ct': $order_by = 'category ASC'; break; case 'pl': $order_by = 'place ASC'; break; default: $order_by = 'term ASC'; $sort = 'te'; break;} 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 More sharing options...
Larry Posted February 22, 2014 Share Posted February 22, 2014 Thanks for the nice words. I'm glad the book has been helpful. I'm not sure what you mean by "The sort works, but it sorts all data, not limiting itself to the data from the query". Could you explain? Link to comment Share on other sites More sharing options...
Beltic Posted February 22, 2014 Author Share Posted February 22, 2014 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. Thanks! Link to comment Share on other sites More sharing options...
HartleySan Posted February 22, 2014 Share Posted February 22, 2014 When you say it "is not limiting itself to the user query", do you mean that the sort is not limited to just the results displayed on one page?I'm still confused. Link to comment Share on other sites More sharing options...
abigail Posted February 24, 2014 Share Posted February 24, 2014 I think it is your query that is wrong and not the sort. Link to comment Share on other sites More sharing options...
Larry Posted February 24, 2014 Share Posted February 24, 2014 Yeah, I think your logic that limits what rows are selected isn't being implemented when you're doing the sort. I'd print out the query being executed to confirm this. Link to comment Share on other sites More sharing options...
Beltic Posted October 7, 2014 Author Share Posted October 7, 2014 I figured out what it was. I wasnt appending variables for my query to the sort URL. I had this, http://medieval.name/browse_search_results.php?sort=te Instead I needed this, http://medieval.name/browse_search_results.php?term=saxon&sort=te Then it worked fine. Link to comment Share on other sites More sharing options...
Larry Posted October 8, 2014 Share Posted October 8, 2014 Ah...that would do it! Kudos for figuring it out and thanks for letting us know. Link to comment Share on other sites More sharing options...
Recommended Posts