Jump to content

Archived

This topic is now archived and is closed to further replies.

presso

just using one query

Recommended Posts

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.

Share this post


Link to post
Share on other sites
ahhhh , nice and easy , i knew it would be but could not quite figure it out , thanks for that  :)

Share this post


Link to post
Share on other sites
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 it
echo "<a href = '{$_SERVER['PHP_SELF']}?sortby=name'>Name</a>";
.
.

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.