i am outputting database entries with the following code:
<div id="main_area">
<div id="container">
<div id="php_container" role="main">
<?php
include('connect_it.php');
$sqlget= "SELECT * FROM dbtablename";
$sqldata= mysqli_query ($dbcon,$sqlget) or die('this is an error');
while ($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
echo $row[ 'li' ] ;
}
?>
</div>
</div>
</div>
on page load, i’d like the database entries to be ordered by their date (from most recent to least recent) which is stored in a mysql field called ‘added’ in the format DD/MM/YY.
i’m not sure if it can be done, but as another option, the date is within a span defined by <span id="date">date: 27/11/11</span> so perhaps this span could be used to order the data?
so my question is, how can i make the initial output ordered by date from most recent to least recent?
i have tried:
$sqlget= "SELECT * FROM dbtablename ORDER BY added ASC";
but i got unexpected results.
thank you.
If your added column is a DATE, DATETIME or TIMESTAMP type you can use DATE_FORMAT like so,
See, https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
Otherwise if it is a string try (it really should be a DATE type though),
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date