Fetching array then reversing it


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I have a simple problem, I'll try to explain it as best I can:
News entries in my database are ordered from oldest to newest. In order to pull out the last 10 lines I do this:
$newsquery=mysql_query("SELECT * FROM news ORDER BY timestamp DESC LIMIT 10");
while($row = mysql_fetch_array($newsquery)){
echo '<b>' .$row['line']. '</b>
';
}
It spits out something like this:
most recent news in db
second most recent news in db
third most recent news in db
etc...

The problem is I need to flip that list so the oldest of the 10 is on top and the newest is on bottom.

What I've tried:
$row = array_reverse(mysql_fetch_array($newsquery)))
array_reverse didn't seem to do anything.

I've also read that it can be done with a subquery, but the explanation wasn't that great.
Any help would be much appreciated!

No comments posted yet

Your Answer:

Login to answer
77 Like 8 Dislike
Previous forums Next forums
Other forums

using a loop help
Hi guys , i need some help. I have this loop :
while ($row = mysql_fetch_assoc($Result)) { ?&

PEAR Email Attachment w/ $gpg
I have no issues with this code if I take out the attachement section and include the info in the em

shoping cart issues
i´ve wrote this and works when i add an item to, my cart, but when i want to add othrer item just

Google Map
I have done Google Map Integration for one my project. But for that we need the "latitude and l

Port scanner problem
Hai
recently i developed one app through which u can check the opened and closed ports under an

Working with popups and such in a class
I've recently started building my applications completely enclosed in classes. I like the fact that

this code is strange !
Hi i got this code from the web.. It checks for live and dead socks
It is working perfectly on my

Can I use a loop
Hi buddies!

Once again with my doubts here.

Right now I am using this sql stat

How to use Substr
I want to check for the word CATEGORY: inside a string which can be CATEGORY: ITEM
and remove the

List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash