Uploads Per Page

14 posts by 3 authors in: Forums > CMS Builder
Last Post: August 21, 2018   (RSS)

By KennyH - August 20, 2018

Is there a way to get uploads limited per per page?

For example, a client is using CMSB as a gallery subscription website. Each album can have 500 to 1000 pictures. I would like get the pictures to display about 50-100 per page instead of trying to load all of them at the same time.  I don't think I have ever done this, so I am needing some help.

Thanks in advance

Kenny

By Dave - August 20, 2018

Hi Kenny, 

Ok, sure.  Is an album a single record in the CMS?  So there's a single record in the CMS with an upload field that has 500-1000 uploads? Is that correct? 

Dave Edis - Senior Developer
interactivetools.com

By KennyH - August 20, 2018

It's a multi-record section and each record is a separate gallery. Each gallery will have 500+ uploads

By KennyH - August 21, 2018

Hi Daniel - I might not have it down just right because I am getting an error

Error adding symbol table to error log num 367!
MySQL Error: Got a packet bigger than 'max_allowed_packet' bytes

mysql_count() MySQL Error: MySQL server has gone away
- in errorlog_functions.php on line 300 by mysql_count()

Here's what I have

list($chs_galleriesRecords, $chs_galleriesMetaData) = getRecords(array(
'tableName' => 'chs_galleries',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$chs_galleriesRecord = @$chs_galleriesRecords[0]; // get first record

list($uploadRecords, $uploadMetaData) = getRecords(array(
'tableName' => 'uploads',
'perPage' => 50,
'where' => 'tableName = "chs_galleries" AND recordNum = "' . $gallery_imagesRecord['num'] . '"',
'allowSearch' => false,
'loadUploads' => false,
));

<?php foreach ($uploadRecords['gallery_images'] as $index => $upload): ?>
<a href="<?php echo htmlencode($upload['urlPath']) ?>" class="lightbox-portfolio">
<img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" class="img-fluid" alt="<?php echo htmlencode($chs_galleriesRecord['gallery_title']) ?>">
</a>
<?php endforeach ?>

By daniel - August 21, 2018

Hi Kenny,

I think that this line:

'where' => 'tableName = "chs_galleries" AND recordNum = "' . $gallery_imagesRecord['num'] . '"', 

should be:

'where' => 'tableName = "chs_galleries" AND recordNum = "' . $chs_galleriesRecord['num'] . '"',

Give that a shot and see if that helps.

Thanks,

Daniel
Technical Lead
interactivetools.com

By KennyH - August 21, 2018

Unfortunately, that gives me the same error

By daniel - August 21, 2018

Hi Kenny,

I have a couple more things to try: 

1) Can you change 'loadUploads' to false in your first getRecords() call;

2) Can you also change this line:

<?php foreach ($uploadRecords['gallery_images'] as $index => $upload): ?>

to

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

If that still doesn't help, can you check the Developer Log in CMSB (under Admin Menu) and let me know if there are any additional errors being logged there?

Thanks,

Daniel
Technical Lead
interactivetools.com

By KennyH - August 21, 2018

That works except I have had to add to the link it generates. Where does this variable get defined?

<img src="/webadmin/uploads/<?php echo htmlencode($upload['thumbUrlPath']) ?>" class="img-fluid" alt="<?php echo htmlencode($chs_galleriesRecord['gallery_title']) ?>">

By daniel - August 21, 2018

Hi Kenny,

To dynamically generate the upload directory (the portion you bolded), you can add this code below your getRecords() calls:

$schema = loadSchema('chs_galleries');
list($uploadDir,$uploadUrl) = getUploadDirAndUrl($schema['gallery_images']);

$uploadUrl should now contain the directory the images are in. You can then change your image src to:  

src="<?php echo $uploadUrl . htmlencode($upload['thumbUrlPath']) ?>"

Let me know if that solves the issue, or if I can help with anything else.

Thanks,

Daniel
Technical Lead
interactivetools.com