Printing Data from a dB in Reverse Order

He has: 1,380 posts

Joined: Feb 2002

Hey, what I'm trying to do is to either print data from a dB (MySQL) in reverse row order...in other words print row 5, row 4, etc...
OR insert new rows at the top of the table instead of underneath the old ones...knowwhadumsayin? I have no idea how to do this.

Thanks.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

SELECT * FROM table ORDER BY auto_increment_field DESC

He has: 3 posts

Joined: Jan 2004

Maybe that's work (but it's a little bit harder than other variants): you may transfer your info to array, and then print array from end to beggining...

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

As a general rule, it is always best to do your sorting in SQL since it is a bit quicker.

He has: 1,380 posts

Joined: Feb 2002

what value does "auto_increment_field" take?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I meant, sort by a field that is the primary key with auto_increment (usually called "id").

He has: 1,380 posts

Joined: Feb 2002

ok thanks

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.