orderBy Upload Filename?

2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 18, 2012   (RSS)

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)

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/