Reputation: 47
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">'." "; } ?>
Upvotes: 0
Views: 164
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
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
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">'." "; } ?>
Upvotes: 3