List most recent uploads

14 posts by 5 authors in: Forums > CMS Builder
Last Post: December 1, 2008   (RSS)

Hello.

I'm familiar with how to display the most recent records. But, is there a way to display the 5 most recent uploads, for instance, for a certain record?

Thanks, in advance, for the help!

Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com

Re: [dwelling] List most recent uploads

By Jake - July 12, 2008

Hi Jeremy,

Just to clarify, did you need to do this for one specific record only, or all records in a section? Did you want to set this up for a list viewer page or a detail viewer page?

I look forward to hearing from you!
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [Jake] List most recent uploads

Hi Jake! Thanks so much for the response.

I think it would be best in my situation to have it list the 5 most recent uploads among any (all) of the records in the section. As for the second question, the uploads are on the detail pages, but I would like to draw from those and place the most recent ones on the main list page.

Hopefully that makes sense.

Thanks,

Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com

Re: [dwelling] List most recent uploads

By Jake - July 14, 2008

Hi Jeremy,

I tested this code out on my end and it looks like it will do the job for you:

<?php
list($uploadRecords, $uploadMetaData) = getRecords(array(
'tableName' => 'uploads',
'where' => 'tableName = "YOUR_SECTION_TABLE_NAME" && fieldName = "YOUR_UPLOAD_FIELD_NAME"',
'orderBy' => 'createdTime DESC',
'limit' => '5',
));
$upload = @$uploadRecords[0]; // get first record
?>

<?php foreach ($uploadRecords as $record): ?>
<a href="<?php echo $record['urlPath'] ?>"><?php echo $record['info1'] ?></a><br />
<?php endforeach ?>


That code should do the trick on your list viewer page. Just replace "YOUR_SECTION_TABLE_NAME" and "YOUR_UPLOAD_FIELD_NAME" with the correct values from your installation.

Let us know if you need anything else. [:)]
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [Jake] List most recent uploads

Jake,

I've been away from my computer for a couple of days so I haven't tried this yet. But I wanted to at least acknowledge, and thank you for, your post. Your assistance is very much appreciated. I'll let you know how it goes.

Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com

Re: [Perchpole] List most recent uploads

By Dave - July 17, 2008 - edited: July 17, 2008

Hi Perch,

There's no easy way to do that. It would require a bit of custom programming.

One thing you could try is looping over the uploads and then looking up each record one at a time in the foreach loop:

<?php foreach ($uploadRecords as $upload): ?>

// get first record
$recordNum = @$upload['recordNum'];
list($productRecords, $productMetaData) = getRecords(array(
'tableName' => 'catalogue',
'where' => "num = '$recordNum'",
'limit' => '5',
));
$product = @$productRecords[0];

?>

I haven't tried it, but I think that should work the way you want.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] List most recent uploads

By Perchpole - July 17, 2008

Hi, Dave -

Thanks for you input. However, I'd be grateful if you could explain the code a little beeter. There appears to be at least one set of brackets missing and I'm not at all sure where the code block is supposed to go...

Rather flumoxed!

:0)

Perch

Re: [Perchpole] List most recent uploads

By Dave - July 18, 2008

I had missed a slash. I added it above in red. Here's the basic code. I used print_r to display all the variables. Hopefully you can figure it out from this.

<?php
require_once "C:/wamp/www/sb/core2/admin/lib/viewer_functions.php";

list($uploadRecords, $uploadMetaData) = getRecords(array(
'tableName' => 'uploads',
'where' => 'tableName = "news" && fieldName = "uploads"',
'orderBy' => 'createdTime DESC',
'limit' => '5',
));
?>

<?php foreach ($uploadRecords as $upload): ?>

<?php
$recordNum = @$upload['recordNum'];
list($productRecords, $productMetaData) = getRecords(array(
'tableName' => 'news',
'where' => "num = '$recordNum'",
'limit' => '1',
));
$product = @$productRecords[0];
?>

<h2>Upload Fields</h2>
<xmp><?php print_r($upload); ?></xmp>

<h2>Record Fields</h2>
<xmp><?php print_r($product); ?></xmp>

<hr />


<?php endforeach ?>


You'll need to change the table names and a few things, but this should get you on your way. Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] List most recent uploads

By Perchpole - July 20, 2008

Dave -

It works a treat.

Thanks a lot!

:0)

Perch