Sorting Uploads

5 posts by 3 authors in: Forums > CMS Builder
Last Post: February 1, 2023   (RSS)

By pacolvin - January 17, 2023

I had some code working that was sorting uploads, but a client made some changes and now I can't seem to get things working again.

What I have is a Detail page that has uploads for meeting minutes.  the info2 field has the date of the upload.  

Below is the load records code and then the code to display and sort the uploads.  I'm hoping someone can see what I'm missing.  The uploads display, but are not sorted in descending order.

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = ['','../','../../','../../../','../../../../']; // add if needed: '/home3/epfctwot/public_html/'
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load record from 'member_section_meeting_minutes'
  list($member_section_meeting_minutesRecords, $member_section_meeting_minutesMetaData) = getRecords(array(
    'tableName'   => 'member_section_meeting_minutes',
    'where'       => '', // load first record
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $member_section_meeting_minutesRecord = @$member_section_meeting_minutesRecords[0]; // get first record
  if (!$member_section_meeting_minutesRecord) { dieWith404("Record not found!"); } // show error message if no record found

?>
<?php
//get uploads for current record
$uploads = mysql_select('uploads', "tableName='member_section_meeting_minutes' ORDER BY STR_TO_DATE(info2,'%m/%d/%Y') DESC");
?>

<?php foreach ($member_section_meeting_minutesRecord['member_section_meeting_minutes'] as $index => $upload): ?>
<a href="/cmsb/uploads/<?php echo htmlencode($upload['urlPath']) ?>" style="font-family: 'Lato', sans-serif; font-size: 16px; font-weight: 300;"><?php echo htmlencode($upload['info1']) ?></a>            
<br>
<?php endforeach ?>

Thanks

By Dave - January 30, 2023

Hi pacolvin, 

I notified no one responded to this post.  Did you figure it out?  If not I'll take a look.  Thanks!

Dave Edis - Senior Developer
interactivetools.com

By pacolvin - January 30, 2023

Hi Dave,

I have not figured this one out yet.  Any help would be greatly appreciated.

Phil

By kitsguru - February 1, 2023

you are sorting month day year which will group first by month whch is OK if you only have one year of data. Since it is a string it sorts as a string not a date.

Change it to yyyy-mm-dd to get it in date order

Jeff Shields