Quote from: Briggsy at Sep 11, 2006, 05:57 AM
In the example below it is in VARCHAR because DATE turned it into YYYY-MM-DD. The CSV that I used to upload the data was it in DD-MM-YY which is also the same format as I wanted it shown on the site.
I can get the CSV changed but still need to show it in DD-MM-YY on website. FOund a few SQL querys and PH codes to do it but couldn’t get them to work (don’t know enough)
Two approaches to sorting properly and displaying any format...
1. Store as unix timstamp or datetime in MySQL; MakeTable can then sort by the actual field name and you can use something like this to convert the output when assigning the column values to each row of the result set array:
<?php
...
'StartDate' => strftime('%d-%m-%y', strtotime($row['Start']),
...
?>
and then when creating the table headers:
<?php
...
'StartDate'=> $objTable->prepareOrderByLink('Start', 'Start Date'),
...
?>
The first param in prepareOrderByLink is the actual column name to sort by, and the second is the label for the table header column.
2. Without changing the db, you can use strtotime to convert that European date format to a unix timestamp (as in the above example) and make that concatenated with the id field, the key of each array element; you can then simply krsort() the results to order them properly:
<?php
...
$results= array ();
// loop through result of query and assign each row of values
foreach ($rs as $row) {
// create a sortable key in format {Start}-{Code}
$rowKey= strtotime($row['Start']) . '-' . $row['Code'];
$results[$rowKey]= array (
'Code' => $row['Code'],
...
);
}
...
// Order array in reverse by key
krsort($results);
...
?>