Philb24
Philb24

Reputation: 67

Sorting Database images by date

I have a basic upload and gallery view for photos. However, the view for the gallery is by oldest first.

Can someone show me an easy way for me to sort this by newest first? This is my PHP which shows the images:

<?php
   $sql="SELECT * FROM chiseldonuploads";
   $result_set=mysql_query($sql);

   while($row=mysql_fetch_array($result_set));
   {
?>
       <img class="photos" src="uploads/<?php echo $row['file'] ?>"></td>
<?php
   }
?>

Upvotes: 0

Views: 248

Answers (1)

pavlovich
pavlovich

Reputation: 1942

In case your table chiseldonuploads has column date, for example created_date you can order it by date, or if it does not have date, you can try ordering by id of the table:

 $sql="SELECT * FROM chiseldonuploads ORDER BY id DESC";

Here id has to be replaced with column name representing id column in your table. But if you have date column, you have to order by date.

Upvotes: 2

Related Questions