Sort Uploads by createdTime

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 21, 2012   (RSS)

Re: [pcolvin] Sort Uploads by createdTime

By Jason - February 20, 2012

Hi,

You have the right idea. What's happening is that you're querying the uploads table to retrieve records for only the first gallery record, not all of them. What we can do is stop the getRecords call from getting uploads (no point doing it twice), and then getting upload records for each gallery record inside the foreach loop.

For example, start by turning off uploads for gallery records:

// load records
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'loadUploads' => false,
));


Next, in your foreach loop, query the uploads table for the uploads associated with the current record:

<?php foreach ($galleryRecords as $record): ?>

<h2><?php echo $record['category'] ?><br/></h2>

<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
<tr>
<?php
//get uploads for current record
$uploads = mysql_select('uploads', "tableName='gallery' AND fieldName = 'photos' AND recordNum='".intval($record['num'])."' ORDER BY createdTime DESC");
?>
<?php foreach ($uploads as $upload): ?>

<td>

<?php if ($upload['thumbUrlPath']): ?>
<a href="<?php echo $upload['urlPath'] ?>" rel="lightbox[<?php echo $record['num'] ?>]" title="Description: <?php echo $upload['info1'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
</a>

<?php else: ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />

<?php endif ?>

</td>

<?php $maxCols=4; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>

</tr>
</table>
<?php $count=0 ?>
<hr/>
<?php endforeach ?>


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/

Re: [pcolvin] Sort Uploads by createdTime

By pcolvin - February 21, 2012

Jason,

Thanks. It works perfectly!

Phil