Just a little query, I am making a system for the admin area of cubecart so that the admin of the site can add news and it will be posted on the main page. I will try and explain in as much detail as possible.
Here goes, I have my database 'simfree_chadwicks' and the table 'store_news' with the fields 'id' 'date' 'news'. The 'id' field automatically counts from 1 upwards and gives the news an ID number.
In news.php (it displays the information from the database) the results are ordered by id. Now here is my problem, when it loads the information from the database it shows the oldest record first, how do I make it show the latest addition first?
Here is my code:
CODE
$query= "SELECT * FROM ".$prefix."store_news where id > 0 LIMIT 5";
$result = mysql_query($query);
$total_rows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
$id=$row["id"];
$date1=$row["date"];
$news=$row["news"];
if($total_rows==0)
{
echo"No news at the moment";
}
if($total_rows>0)
{
// start table to display news
?>
<p align="left">
<u>
<?php echo "$date1"; ?>
</u>:<br><br>
<?php echo "$news"; ?>
</p>
<br>
<?php
}
}
//end
?>
$result = mysql_query($query);
$total_rows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
$id=$row["id"];
$date1=$row["date"];
$news=$row["news"];
if($total_rows==0)
{
echo"No news at the moment";
}
if($total_rows>0)
{
// start table to display news
?>
<p align="left">
<u>
<?php echo "$date1"; ?>
</u>:<br><br>
<?php echo "$news"; ?>
</p>
<br>
<?php
}
}
//end
?>
Any help is grately appreciated.
Regards,
Paul