Robske
Robske

Reputation: 57

Display last uploaded image

I working on an image gallery with the thumbnails and main image on the same page. I have ordered the thumbnails so that the last uploaded image standing on top but I also want that this image is displayed as main image. My site is http://www.robcnossen.nl/view_album.php?album_id=7

I can't find if it can be done with mysql but maybe I am looking right. I'm trying to find the solution in PHP but all what I find on internet I can't get it working for me.

I thought that array multisort, filectime and ksort would solve my problem but nothing changed. A part of my code is;

print_r ($images);
//$dirname = dirname(__FILE__);
//filectime($dirname);
//ksort($images);
array_multisort($images, SORT_DESC);
if(isset($image['album'], $image['id'], $image['ext']));     
    $foto = 'uploads/' . $image['album'] . '/' . $image['id'] . '.' . $image['ext'].   '';

$standaardwaarde=isset($_GET['image_id']) ? $_GET['image_id'] :$foto;

echo'<img src="' ,htmlentities($standaardwaarde), '" title="" />'; 

How can the last uploaded image be shown as main image?

Upvotes: 0

Views: 392

Answers (2)

kawashita86
kawashita86

Reputation: 1573

If you store it in a mysql database and your image are stored with an auto increment field or a date field you can use the ORDER BY clause to get the last image as the first (inverse order):

ORDER BY id DESC or ORDER BY timestamp DESC.

your main image will be then:

$retrieved_array[0]['field_to_show']

Upvotes: 0

Omnisite
Omnisite

Reputation: 287

If the $images is a return variable from a DB query, you can change that query by adding an ORDER BY timestamp (I see on your var_dump that there is a timestamp).

Upvotes: 1

Related Questions