Page 1 of 1

backwards database.....

Posted: Thu Jan 30, 2003 10:03 am
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

Posted: Thu Jan 30, 2003 1:29 pm
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.

Posted: Thu Jan 30, 2003 2:23 pm
by AndrewBacca
cheers, ive just added an ID for each news post so Ill sort it by that

thx

Andrew