dbTalk Databases Forums  

Get the results in reverse order

comp.databases.mysql comp.databases.mysql


Discuss Get the results in reverse order in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SM
 
Posts: n/a

Default Get the results in reverse order - 06-09-2010 , 01:46 PM






Hello,

I've created a query that returns rows sorted by date. From the newest
to the oldest.

I need to get the first element, that is the newest, and then the rest
of the elements but in reverse order, that is the oldest to the
newest

ie.:

id, name, date
----------------------
12 item4 2010-12-25
16 item34 2005-11-5
123 item2 2001-10-15
91 item925 1996-8-8
82 item7 1992-3-12
145 item445 1989-10-6
283 item8 1985-5-1
675 item53 1978-2-4
345 item12 1976-7-7
72 item91 1963-5-17


output should be:
---------------------
12 item4 2010-12-25
72 item91 1963-5-17
345 item12 1976-7-7
675 item53 1978-2-4
283 item8 1985-5-1
145 item445 1989-10-6
82 item7 1992-3-12
91 item925 1996-8-8
123 item2 2001-10-15
16 item34 2005-11-5

I know hot to get the first row, like this:

$firstRow = $result->fetch_assoc()

and the rest of the elements like this:

while( $row = $result->fetch_assoc() ) {
CODE GOES HERE
}

How do i get the rest of the rows in reverse order? Is this possible?
What would be the appropiate technique?

Thanks
Marco

Reply With Quote
  #2  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: Get the results in reverse order - 06-09-2010 , 07:19 PM






On Jun 9, 6:46*pm, SM <servandomont... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

I've created a query that returns rows sorted by date. From the newest
to the oldest.

I need to get the first element, that is the newest, and then the rest
of the elements but in reverse order, that is the oldest to the
newest

ie.:

id, name, date
----------------------
12 *item4 * 2010-12-25
16 *item34 *2005-11-5
123 item2 * 2001-10-15
91 *item925 1996-8-8
82 *item7 * 1992-3-12
145 item445 1989-10-6
283 item8 * 1985-5-1
675 item53 *1978-2-4
345 item12 *1976-7-7
72 *item91 *1963-5-17

output should be:
---------------------
12 *item4 * 2010-12-25
72 *item91 *1963-5-17
345 item12 *1976-7-7
675 item53 *1978-2-4
283 item8 * 1985-5-1
145 item445 1989-10-6
82 *item7 * 1992-3-12
91 *item925 1996-8-8
123 item2 * 2001-10-15
16 *item34 *2005-11-5

I know hot to get the first row, like this:

$firstRow = $result->fetch_assoc()

and the rest of the elements like this:

while( $row = $result->fetch_assoc() ) {
* *CODE GOES HERE

}

How do i get the rest of the rows in reverse order? Is this possible?
What would be the appropiate technique?

Thanks
Marco
Please DO NOT MULTI POST!
Crosss post if you must but DO NOT MULTI POST. It wastes people's
time.
http://www.blakjak.demon.co.uk/mul_crss.htm

Reply With Quote
  #3  
Old   
Erick T. Barkhuis
 
Posts: n/a

Default Re: Get the results in reverse order - 06-10-2010 , 02:07 AM



SM:


Quote:
ok thanks guys. The common solution is that i have to use an array and
the appropriate functions to do what i'm looking for...
"Common solution"?
You've only received one reply!


--
Erick

Reply With Quote
  #4  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: Get the results in reverse order - 06-10-2010 , 04:56 AM



On 10 June, 07:07, "Erick T. Barkhuis" <erick.use-... (AT) ardane (DOT) c.o.m>
wrote:
Quote:
SM:

ok thanks guys. The common solution is that i have to use an array and
the appropriate functions to do what i'm looking for...

"Common solution"?
You've only received one reply!

--
Erick
No, he multi posted to clp

Reply With Quote
  #5  
Old   
John Nagle
 
Posts: n/a

Default Re: Get the results in reverse order - 06-21-2010 , 02:57 AM



On 6/9/2010 10:46 AM, SM wrote:
Quote:
Hello,

I've created a query that returns rows sorted by date. From the newest
to the oldest.

I need to get the first element, that is the newest, and then the rest
of the elements but in reverse order, that is the oldest to the
newest

ie.:

id, name, date
SELECT id, name, date FROM whateveryourtablenameis
ORDER BY DATE DESC;

Read the SELECT statement manual page from the MySQL manual.

John Nagle

Reply With Quote
  #6  
Old   
Erick T. Barkhuis
 
Posts: n/a

Default Re: Get the results in reverse order - 06-21-2010 , 03:03 AM



John Nagle:

Quote:
On 6/9/2010 10:46 AM, SM wrote:
Hello,

I've created a query that returns rows sorted by date. From the
newest to the oldest.

I need to get the first element, that is the newest, and then the
rest of the elements but in reverse order, that is the oldest to the
newest

ie.:

id, name, date

SELECT id, name, date FROM whateveryourtablenameis
ORDER BY DATE DESC;

Read the SELECT statement manual page from the MySQL manual.
Errr....John, this is Monday morning and you haven't had any coffee,
yet. Right?
:-)

--
Erick

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.