Zak Ferris
Zak Ferris

Reputation: 47

how do I reverse the order of my images being pulled in and displayed on my website with PHP

I need to change the order of my results largest number first

 <?php $files = glob("blog/*.*"); for ($i=1; $i<count($files); $i++) { $num = $files[$i]; echo '<img src="'.$num.'" alt="random image">'."&nbsp;&nbsp;"; } ?>

Upvotes: 0

Views: 164

Answers (3)

IROEGBU
IROEGBU

Reputation: 948

You could use array_reverse ($files) to reverse the order of the values of the array... then use the loop you are currently using

Upvotes: 1

Avinesh Kumar
Avinesh Kumar

Reputation: 1509

If you are storing the image in mysql as blob, then you can write an SQL with order by desc clause. example:

select image from image_repo order by image_id desc

Upvotes: -1

sberry
sberry

Reputation: 132018

How about just reversing the order of the loop?

<?php $files = glob("blog/*.*"); $i = count($files) - 1; for ($i; $i>=0; $i--) { $num = $files[$i]; echo '<img src="'.$num.'" alt="random image">'."&nbsp;&nbsp;"; } ?>

Upvotes: 3

Related Questions