Jump to content

just using one query


presso

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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.