Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: php array_reverse how is it used

Original Message
Name: BigShow
Date: April 7, 2008 at 14:53:20 Pacific
Subject: php array_reverse how is it used
OS: xp
CPU/Ram: pentium
Model/Manufacturer: 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


Report Offensive Message For Removal

Response Number 1
Name: Laler
Date: April 7, 2008 at 18:51:58 Pacific
Subject: php array_reverse how is it used
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 2
Name: Michael J (by mjdamato)
Date: April 7, 2008 at 20:30:02 Pacific
Subject: php array_reverse how is it used
Reply: (edit)
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


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: php array_reverse how is it used

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC