presso Posted October 22, 2006 Share Posted October 22, 2006 I am wondering what the best way of pulling the data i need out of one query where i need two different instances of the data. ie[code]$query = $DB->query("SELECT name, location, date FROM table ORDER BY name DESC LIMIT 10");[/code]now say i am using a query like that , the first output sorts the display by name , but what if i want to just a little further down the page want to display the same info but sorted by location , do i have to do another query or can i just use the first query. If somebody could point out the obvious for me would be great. Quote Link to comment https://forums.phpfreaks.com/topic/24769-just-using-one-query/ Share on other sites More sharing options...
.josh Posted October 22, 2006 Share Posted October 22, 2006 [code]foreach ($query['location'] as $val) { $sortloc[] = $val;}sort($sortloc);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24769-just-using-one-query/#findComment-112777 Share on other sites More sharing options...
presso Posted October 22, 2006 Author Share Posted October 22, 2006 ahhhh , nice and easy , i knew it would be but could not quite figure it out , thanks for that :) Quote Link to comment https://forums.phpfreaks.com/topic/24769-just-using-one-query/#findComment-112841 Share on other sites More sharing options...
.josh Posted October 23, 2006 Share Posted October 23, 2006 although... if you have the exact same info further down the page, except sorted a different way, wouldn't it be better to make the list titles (name, location, date) links that the user can click on, and when they do, the page reloads, but runs the query with a different sort by in it? that way you would have less stuff taking up your page and less bandwidth being used (for having more stuff being displayed). example:[code]..$titles = array('name','location','date');$sortby = (in_array($_GET['sortby'],$titles)) ? $_GET['sortby'] : 'name';$query = $DB->query("SELECT name, location, date FROM table ORDER BY $sortby DESC LIMIT 10");..// use this in your list titles/headers/whatever you call itecho "<a href = '{$_SERVER['PHP_SELF']}?sortby=name'>Name</a>";..[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24769-just-using-one-query/#findComment-112971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.