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

MS are the best!!!
Visit http://www.microsoft.com/australia/windows/default.aspx?h=watch-a-demo and click the massive '

Performance impact of cookies
Hi, I was just wondering what impact there would be in terms of performance if you where to set then

have trouble in a if condition
The if below is working ok, it check when indexes, name, zipcode and state are empty.
Code: &

Sequencing or queuing parallel process
Scenario is as follows
There is one parent process say P1 and 4 child processes say A B C D

Problem with PHP/mySQL login code
Hello,

There is an error in my login script and I can't figure out what it is...
I believe

$get problem
Hi Guys ...

can you please tell me what i am doing wrong here
Code: <?php

Giving the below syntax error
Dear Experts,

I have used 2 buttons in gui status as display and cjhange.When the user wi

Embedding flash object in Else statement
This is my first major project in PHP and I'm having some trouble embedding a flash object in an Els

Allegro crashes when running load_bitmap. Why?
I can not get Allegro to load any BMP images. Here is a section of test code. The picture is in the

Undefined Variable: PHP_SELF, pls help
Hi,

Im a newbie on PHP / MySQL programming and Im running a script to search one field on my

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