![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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... |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |