I have some php code that creates divs based on my database information. I want it to look through and show the newest first. I tried several things with no success. Any help is appreciated!
function filldiv() {
$loopResult .= '';
$events = mysql_query('SELECT * FROM a3825952_blog.Blog');
while($row = mysql_fetch_array($events)) {
$loopResult .= '
<div class="blogbox">
<div class="blogtitle">'.$row['TITLE'].'</div>
<div class="blogdate">'.$row['DATE'].'</div>
<div class="blogcontent">'.$row['CONTENT'].'</div>
<div class="blogimage"> <img src="'.$row['IMAGE'].'"/></div>
<div class="blogimage"> <img src="'.$row['IMAGEB'].'"/></div>
<div class="blogimage"> <img src="'.$row['IMAGEC'].'"/></div>
</div>
';
}
echo $loopResult;
}
}
Use an ORDER BY clause in your select statement:
SELECT * FROM a3825952_blog.Blog ORDER BY `date` DESC
See http://www.w3schools.com/php/php_mysql_order_by.asp for some tutorials to start with.