I have here a foreach loop that displays images from a database onto a webpage. What I would like to do is iterate through the foreach loop backwards, so the latest content is shown first on the webpage. Here is my code:
$sql = "SELECT COUNT(*) FROM 'UPLOADPICS'";
if ($sth = $dbhandle->query($sql)){
if ($sth->fetchColumn() > 0){
$sql = "SELECT link FROM 'UPLOADPICS'";
foreach ($dbhandle->query($sql) as $row){
$content = $row['link'];
?>
<img src="<?php echo $content ?>" />
<br/>
<br/>
<?php
}
}
else {
print "No rows matched the query";
}
Is this possible? Thanks so much in advance!
if you don’t have a date field in your table .. you can order by id in a Descending order
if you don’t like that you can use array_reverse() function