mysql swap 2 rows

I have a table of images which contains 3500 records.
The site is already live.
Now, in the frontend i want to change the display order of images.
Right now it displays in the order it is inserted.
I wrote code so that the ids can be swapped from backend but even then it won't help.
Its now not possible for me to change queries in frontend in each and every location to write  " order by id"
Is there any other way out ??
Right now when i say :
SELECT id, imageh, imagew, filename FROM picture WHERE pictures_siteid =212 LIMIT 13
it displays
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ioannis AnifantakisSoftware EngineerCommented:
SELECT id, imageh, imagew, filename FROM picture WHERE pictures_siteid =212 order by id DESC LIMIT 13;

if you make "DESC" at the order by then it orders in "descending" motion.
if you don't put "DESC" it assumes "ASC" which is the "ascending motion"


>order by id
is similar to
>order by id ASC
and will give you ordering from lower to higher numbers

>order by id DESC
will give you descending ordering, that is from the higher to the lower value
Ioannis AnifantakisSoftware EngineerCommented:
Other than that, you can put a timestamp in your table to ensure that no matter what the id, if you make "order by mytimestamp desc" you will for sure get descending ordering.

Unfortunatelly there is no other way arround it
Desire2changeAuthor Commented:
i don't want to change the queries in the frontend.
right now in frontend the order is set as they are inserted
is there a way that without disturbing the frontend , i can change the order of data in database
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Ioannis AnifantakisSoftware EngineerCommented:
I am sorry, but I don't follow you.
You wish to change the way your data comes, without changing your query???

What do you mean by "frontend"?

Explain me and I might be able to understand so I can help you
Chris StanyonWebDevCommented:
You can alter the order of the data in the table by ALTERing it with an ORDER BY clause:


Once you've run this query, then the 'default order of the table will be changed, so if you call the query SELECT * FROM foo, it will be ordered by 'key'.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Desire2changeAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.