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

need help about
i store the value of my select statement result to an array and stored it to a variable named $fname

PHP referral database. I would like this form to email the referrer.
Okay, Hello I've been trolling for years. This the first time I've ever asked for php help. Normally

whats wrong with my code please help!!!
this is the error


Warning: mysql_close(): supplied argument is not a valid MySQL-Link res

Why Are These Functions Causing MASSIVE Memory Problems? Please Help!
Hi,

I have a script with some options.

I use regex to replace patterns in strings, but

Multithreading design
Hi

I have come up with a Singleton class that manages a pool of database connections. Basical

Reading Most Recent CSV File in Directory
I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to m

Can we convert non uni code system into unicode
Hi All,

Presently i am using non-unicode system and the sap version is 4.7.
Can i c

Find only certain URLs from page ... regex (semi-complete script)
Hi guys,

What I need to do is take a page & extract all the URLs from the page &a

Login Functionality Working Different on IE
This is an odd one, I have a site which has an admin section. The admin pages unsurprisingly require

Create or replace package is ending ORA-21700
Database 9.2.0., patch 8 (9.2.0.8.0).
I trying run
create or replace package ....etc.

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