Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order most recent first, oldest last vertically

Status
Not open for further replies.

leeboycymru

Programmer
Jan 23, 2007
185
GB
I have a page that is outputting news vertically, and its ordering oldest first most recent last, and i would prefer the opposite.

The code is below:

<?php
include "config.php";
session_start();
include("config.php");

$sid=session_id();
$date=date("Y-m-d");
$sql="select * from usr where sid='$sid' AND ddate='$date' AND pageno=14";
$q=mysql_query($sql) or die(mysql_error());
$c=mysql_num_rows($q);

$usrcnt=0;
if($c<1)
{
$q1=mysql_query("insert into usr(sid,ddate,pageno) values('$sid','$date',14)") or die (mysql_error());

$q3=mysql_query("select count(*) from usr where pageno=14") or die (mysql_query());
$r3=mysql_fetch_row($q3);
$usrcnt=$r3[0];
}
else
{
$q2=mysql_query("select count(*) from usr where pageno=14") or die (mysql_query());
$r2=mysql_fetch_row($q2);
$usrcnt=$r2[0];
}

?>

and here is code on the page:

<!-- news starts -->
<?
$qu=mysql_query("select * from tbl_news") or die (mysql_error());
while($r=mysql_fetch_assoc($qu))
{?>
<tr>
<td><div align="justify"><span class="thomsan">
<?= $r['Nom_New'] ?>
</span><span class="innerpagetext"><br/>
<?= $r['Desc_New'] ?>
</span></div><br/><hr/>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<? }
?>
<!-- news ends -->

Cheers

Lee
 
You need to change this to be sorted the other way. I suppose you store a date somewhere in the news table, so you would do this:
Code:
            $qu=mysql_query("select * from tbl_news [b]order by date desc[/b]") or die (mysql_error());
 
cheers

i should have seen that sorry, i use more asp that php and didnt realise it was the same.

lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top