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)){
Did you know?Explore Trending and Topic pages for more stories like this.
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

Wierd if else problem
Hi guys,

this probably aint wierd for you, but it seems like php is playin up to me. may b i

What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin

A rank users order by points
I want to make an insert from table 'rank' , with number (rank) from the cod blow, to fild users.ran

MySQL noob question
hi guys

I have a simple mysql table set up, along the lines of

Col 1 - Col 2 - Date_l

How do I create a 2D game "camera" to follow player?
In J2ME programming I'm targeting MIDP 2.0 devices.

I'm using gamecanvas and I was thinking t

use an array from 1 class in a second class
I have a class that adds data to an array

Then I have a second class and I need to check if t

Applet JTextField Size Problem
Hello,

I recently started making an applet to calculate certain values for airplanes. However

UDS 4.0 Datatype issue
UDS 4.0.322 -- connecting to NI Labview 9.0

When using connection method: Cache with live

Filtering an Array Based on Value
I have a very simple script set up that pulls data from a database and is output using this code:

help connecting a form to php and then emailing the form
Ok. So, I made a form, and I need help to where when submitted, I get an email with the submitted de

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