Computing.Net > Forums > Web Development > php array_reverse how is it used

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

php array_reverse how is it used

Reply to Message Icon

Name: BigShow
Date: April 7, 2008 at 14:53:20 Pacific
OS: xp
CPU/Ram: pentium
Product: dell
Comment:

hey guys, I created a news blog and I need the info to come out of the database backwards so that the newest news is on top. I figure to use array_reverse. I am getting errors. Can you look at the code and see what I am doing wrong.


$query = 'SELECT * FROM news_blog';

$result = mysql_query($query) or die(mysql_error());

$result2 = array_reverse($result);


while(isset($result2)){
echo $row['div_date'].$row['date_info'].$row['close_div'].$row['div_news'].$row['news_info'].$row['close_div2'];

}

i know its a stupid error but ive been looking at code for 10 hours and cant take it anymore.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: April 7, 2008 at 18:51:58 Pacific
Reply:

mysql_query() will do the query

mysql_fetch_assoc() or mysql_fetch_array(), etc., will fetch the query result.

See where you got it wrong?

-----

One more thing. Another best practise when developing is
to verbose all errors/warnings. You've used to use
mysql_error() which is good, but it will only verbose errors
on MySQL-related functions.

But if you put error_reporting(E_ALL) on top of your script,
I strongly believe that $result2 = array_reverse($result);
will produce a warning*


Tthe ability to use error_reporting(E_ALL) is controlled by
your server setting (your hosting company).

---
Fubar


0

Response Number 2
Name: Michael J (by mjdamato)
Date: April 7, 2008 at 20:30:02 Pacific
Reply:

A mysql result set is NOT an array - it is a resource pointer. So you cannot use array functions on it. Why would you want to use an array command anyway, just use the database to sort the records based upon the date of the record. You would aslo not use isset() in a while loop when returning records from a query result.

$query = 'SELECT * FROM news_blog ORDER BY submit_date DESC';

$result = mysql_query($query) or die(mysql_error());

while ($record = mysql_fetch_assoc($result)) {

//Insert code to display the records

}

Michael J


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Keep unknown video.. PHP IDEs



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: php array_reverse how is it used

How does it look? www.computing.net/answers/webdevel/how-does-it-look/982.html

ir4dex - what is it and how to fix? www.computing.net/answers/webdevel/ir4dex-what-is-it-and-how-to-fix/362.html

Is it possible to use javascipt to www.computing.net/answers/webdevel/is-it-possible-to-use-javascipt-to-/3138.html