backwards database.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

backwards database.....

Post by AndrewBacca »

I have a database that I store news posts in.
Then I display them on my news pages, it all works fine no errors, but...

I want to have the last record in the database at the top of the page instead of the bottom, any ideas how?
heres the code ive got at the moment :

Code: Select all

$query = "SELECT * FROM News";
		$result = mysql_query($query);
		while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
		{	  
		$date =  $rowї'Date'];
		$time =  $rowї'Times'];
		$news =  $rowї'News'];
		$poster =  $rowї'Postedby'];
print "<table width=100%>
		<tr>
<td  bordercolor=#0000A0>
<font class=headings>
<center>|| "; 
print "$date";
print " -- "; 
print "$time";
print "(GMT) ||
<br> _________________________
</center>
</font> <font class=body>";
print "$news ";
print "<p align=right><font class=headings>Posted By : </font>
<font class=body>$poster </font><p align=center>
<font class=headings> _______________<p> </font>
Thanx

Andrew
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

If you have a date/time column in your NEWS table, you can simply sort it in descending order by that column:

Code: Select all

$query = "SELECT * FROM News ORDER BY date_added DESC";
If you have an auto-increment column, you could sort by that instead and get the same effect.
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

cheers, ive just added an ID for each news post so Ill sort it by that

thx

Andrew
Post Reply