Forums

Show (date) records ascending

SPABO 25 Oct, 2013
After working some time with the code as showed below (tx to the Chrono Team!), I would like to know if it would be possible to show the dates in a ascending order.

The 'datum' field is a txt format eg 20-01-2013.

Tx in advance

Rgds
Spabo


<?php
$db = JFactory::getDBO();
$query = 'SELECT %2$s FROM %1$s GROUP BY %2$s ORDER BY %2$s';
$pst = sprintf($query,
  $db->nameQuote('J25_chronoforms_data_TABLENAME'),
  $db->nameQuote('datum')
);
$db->setQuery($pst);
$items = $db->loadObjectList();
?>

<div class="ccms_form_element cfdiv_select" id="datum_container_div"><label for="datum">Wedstrijddatum</label><select size="1" class=" validate['required']"id="datum" title="Vul hier uw keuze in." select name="datum">
<option value="">Kies wedstrijddatum</option>

<?php
foreach ($items as $item) {
  echo('<option value="' . $item->datum . '">' . $item->datum . '</option>');
}
?>
</select>
</div>
<div class="cfclear"></div>
GreyHead 26 Oct, 2013
HI SPABO,

The text format won't sort correctly but if you convert it to a date then I think it will work. Something like
SELECT . . . STR_TO_DATE(`datum`, '%d-%m-%Y') AS date . . . ORDER BY `date`


Bob
SPABO 26 Oct, 2013
Sorry, but I cannot get this sorted out.
Pls give a little bit more (php)assistance
SPABO 06 Nov, 2013
Hi Bob,
Still trying to figure out, but not successfull

I quess the coversion shoud be soemwher in this part
<?php
$db = JFactory::getDBO();
$query = 'SELECT %2$s FROM %1$s GROUP BY %2$s ORDER BY %2$s';
$pst = sprintf($query,
  $db->nameQuote('J25_chronoforms_data_TABLENAME'),
  $db->nameQuote('datum')
);
$db->setQuery($pst);
$items = $db->loadObjectList();
?>


Hope you can help me again.
tx in advance
Rgds
K
This topic is locked and no more replies can be posted.