Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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

![]() |
Keep unknown video..
|
PHP IDEs
|

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