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: [dwelling] List most recent uploads

By Perchpole - July 15, 2008

Hi, All -

I can confirm that this does work. However, on it's own, it isn't ideal as it relies to heavily on "info1" data for identification purposes. I think it would be much more useful if you were to combine this code with the code Dave put together in answer to my random images post...

Forum Link

In this instance, the code not only pulls out the image but also the record that goes with it. In this way you can identify the image with the record name/title as well as providing a link straight back to the record.

I've tried to adapt Dave's code to work with Jake's code (above).


<?php

require_once "/xyz/viewer_functions.php";

list($uploadRecords, $uploadMetaData) = getRecords(array(
'tableName' => 'uploads',
'where' => 'tableName = "catalogue" && fieldName = "images"',
'orderBy' => 'createdTime DESC',
'limit' => '5',
));
$upload = @$uploadRecords[0];

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

?>

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

<a href="<?php echo $product['_link'] ?>"><IMG SRC="<?php echo $record['thumbUrlPath'] ?>" /> <BR /> <?php echo $product['title'] ?></a>

<?php endforeach ?>





The foreach code above is meant to display the thumbnail of the image with the title of the corresponding record underneath. Both the thumb and the the title act as a link back to the record.

Unfortunately, although it does indeed display the thumbs of the 5 most recently uploaded images, the link and title data is only correct in the first instance. The same data is repeated for each of the 4 remaining thumbs.

Is there anyway to fix this?

:0)

Perch

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: [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