Re: Modifying the sort order of a query

From: Date: Thu, 06 Jun 2002 12:10:31 +0000
Subject: Re: Modifying the sort order of a query
References: 1  Groups: php.general php.general 
Request: Send a blank email to php-general+get-101043@lists.php.net to get a copy of this message
Thanks Jay, Well, I went back to work on it, and with the combined suggestions from the list, it's working now. I just had to insert the sub-select on the called page as well. That seemed to be the problem. Thanks for your suggestion -- I used part of it. Regards, Andre On Thursday 06 June 2002 07:39 am, you wrote: > [snip] > I've just tried the sub-select approach. Works great on the first page - > shows names listed alphabetically sorted by country. However, once I click > on > 'Next 20' both sorts go bye-bye (neither by name nor country). > [/snip] > > I am late to the thread but I wanted to offer another suggestion. Retrieve > the data results into an array and sort the array. I like Peter's idea > though, using a case statement for the appropriate sort order information. > You could also set a variable ($lastSortOrder) to 'default', 'country', > 'city', 'whatever' and place this variable within the query. Pseudocode > follows; > > $lastSortOrder = "default" > > $query = "SELECT name, address, city, state, zip FROM table "; > $query .= "ORDER BY " . $lastSortOrder . "; > > <input type="submit" name="action" value="Sort By > Country"><br> > <input type="submit" name="action" value="Sort By > City"><br> > > switch($action){ > case "Sort By Country": > $lastSortOrder = "country" > break; > case "Sort By City": > $lastSortOrder = "city" > break; > } > > I know this isn't complete but I HTH! > > Jay -- Please pray the Holy Rosary to end the holocaust of abortion. Remember in your prayers the Holy Souls in Purgatory. May God bless you abundantly in His love! For a free Cenacle Scriptural Rosary Booklet: http://www.webhart.net/csrb/

« previous php.general (#101043) next »