orderBy Upload Filename?
2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 18, 2012 (RSS)
By Perchpole - June 17, 2012
I’ve created a fairly rudimentary gallery for a site using a simple record system. Each record has a one picture, a caption and a longer description.
The records are loaded into a thumbnail gallery using the following getRecords call:
It works fine. However, I would like to change the order of the image display to one using the filename of the uploaded picture.
(As almost all of the images will be taken from a digital camera - which stamps them with an incremental, numeric filename – they will always appear in the right chronological order, even if some are uploaded at a later date.)
The question is, how do I do it?
:o/
Perch
The records are loaded into a thumbnail gallery using the following getRecords call:
list($galleryTypeRecords, $galleryTypeMetaData) = getRecords(array(
'tableName' => 'record',
'orderBy' => "date DESC",
'perPage' => '12',
));
It works fine. However, I would like to change the order of the image display to one using the filename of the uploaded picture.
(As almost all of the images will be taken from a digital camera - which stamps them with an incremental, numeric filename – they will always appear in the right chronological order, even if some are uploaded at a later date.)
The question is, how do I do it?
:o/
Perch
Re: [Perchpole] orderBy Upload Filename?
By Jason - June 18, 2012
Hi Perch,
One approach would be to loop through your records and combine all the upload fields into a single array, and the sort that array. You can then just output the values of that array.
First, put this function somewhere on your page (the bottom is usually best)
You can loop through your records, combine the upload fields, then sort like this:
EXAMPLE:
Hope this helps
One approach would be to loop through your records and combine all the upload fields into a single array, and the sort that array. You can then just output the values of that array.
First, put this function somewhere on your page (the bottom is usually best)
function sortRecordsByField($records,$fieldName, $direction = "ASC") {
foreach($records as $key => $value) {
$tempArray[$key] = strtolower($value[$fieldName]);
}
if ($direction == "DESC") {
arsort($tempArray);
}
else {
asort($tempArray);
}
foreach($tempArray as $key => $value) {
$sortedRecords[] = $records[$key];
}
return $sortedRecords;
}
You can loop through your records, combine the upload fields, then sort like this:
EXAMPLE:
$images = array();
foreach ($galleryRecords as $gallery) {
$images = array_merge($images, $gallery['images']);
}
$images = sortRecordsByField($images, 'filename');
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/