How to make the number in 'limit' => '1', a variable

9 posts by 2 authors in: Forums > CMS Builder
Last Post: September 27, 2010   (RSS)

By gkornbluth - May 13, 2010

Hi all,

I’m trying to replace the number in the ‘limit’ code in the list records section of my page with a variable so that the number can be pulled from a text field in a single record editor.

Here’s what I thought would work:

list($portfolio_imagesRecords, $portfolio_imagesMetaData) = getRecords(array(
'tableName' => 'portfolio_images',
$maximages = ($common_informationRecord['thumbnail_limit']),
'limit' => '$maximages',
));


But that returns no records no matter what the number in the thumbnail_limit field is.

Any ideas?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] How to make the number in 'limit' => '1', a variable

By Chris - May 13, 2010 - edited: May 13, 2010

Hi Jerry,

A couple thing here. First off, you'll need to move your variable assignment statement up and out of the function call. Secondly, you'll need to either use double-quotes around your variable (single-quotes don't interpolate variables) or just drop the quotes entirely, since they aren't necessary here.

$maximages = $common_informationRecord['thumbnail_limit'];
list($portfolio_imagesRecords, $portfolio_imagesMetaData) = getRecords(array(
'tableName' => 'portfolio_images',
'limit' => $maximages,
));


I hope this helps. If you have any questions, please let me know.
All the best,
Chris

Re: [chris] How to make the number in 'limit' => '1', a variable

By gkornbluth - May 14, 2010 - edited: May 14, 2010

Hi Chris,

Thanks for the tip.

I had tried that but had not removed the single quotes. It's working fine now.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [chris] How to make the number in 'limit' => '1', a variable

Hi Chris,

I’m back at this again.

I’ve been successfully using the $maximages = ($common_informationRecord['thumbnail_limit']) variable on list pages to show a previous / next message when the maximum amount of images per page is exceeded, and to show the remaining groups of images on subsequent pages.

I’ve now got a mult-record editor where each record has an image upload field with an unlimited image capacity. The uploaded images are to be displayed on the detail page for that record.

What I’d like to do is limit the amount of images per page in a similar way that I did for a list page, but I’m stuck getting it to work on a detail page.

I’ve tried everything that I can think of, and the closest that I’ve come is to get pages of images that are pulled from the records in the section, and not the images from the individual record itself.

I just know that I’m going to feel embarrassed when I see what I’ve missed, but I hope you’re willing to embarrass me.

Here’s what I’ve got so far:

At the top of the detail page:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/hsphere/local/home/c307025/cmsAdmin/lib/viewer_functions.php";

list($common_informationRecords, $common_informationMetaData) = getRecords(array(
'tableName' => 'common_information',

'limit' => '1',
));
$common_informationRecord = @$common_informationRecords[0]; // get first record


list($bookRecords, $bookMetaData) = getRecords(array(
'tableName' => 'book',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$bookRecord = @$bookRecords[0]; // get first record


?>

<?php $maximages = ($common_informationRecord['thumbnails_per_page']);
list($bookRecords, $bookMetaData) = getRecords(array(
'tableName' => 'book',
'perPage' => $maximages,

));

?>


And in the body of the detail page:
table width="975" border="0" align="center" cellpadding="5">

<tr>
<td width="474" valign="top">

<?php if ($bookMetaData['totalPages'] > 1): ?>

<span class="body-text-9"><?php echo $common_informationRecord['paging_message'] ?> <?php echo $bookMetaData['page'] ?> of <?php echo $bookMetaData['totalPages'] ?></span>

<?php if ($bookMetaData['nextPage']): ?>
<br /><a class="body-text-bold-9" href="<?php echo $bookMetaData['nextPageLink'] ?>">Click for next page of images</a>

<?php endif ?>
<?php if ($bookMetaData['prevPage']): ?>
<br /><a class=body-text-bold-9" href="<?php echo $bookMetaData['prevPageLink'] ?>">Click for previous page of Images</a>

<?php endif ?><br />

<?php endif ?><br /><br />

<div align="center">

<table border="0" cellpadding="5" cellspacing="0">

<tr>
<td align="left" >
<table cellpadding="5">
<tr>

<?php foreach ($bookRecord['detail_page_images'] as $upload): ?>
<td width="50%" align="left" valign="top" >
<img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight']?>" border="0" style="margin-bottom: 5px" /> </a>

<br />

<?PHP $col = ($common_informationRecord['thumbnail_column_ allowed']); ?>

<div valign="bottom" align="left" ></div>
<?php $maxCols=$col; if (@++$count % $maxCols == 0): ?> </tr>
<tr>
<?php endif; ?>
<?php endforeach ?>

</tr>
</table>


Thanks again for your help,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] How to make the number in 'limit' => '1', a variable

By Chris - September 26, 2010

Hi Jerry,

The perPage feature only works with records, not uploads within a record.

Have a look at [url http://www.interactivetools.com/forum/gforum.cgi?post=75239]this thread[/url], which has a bunch of ideas on how to do paginated uploads.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] How to make the number in 'limit' => '1', a variable

Thanks Chris,

I guess that explains why I couldn't get it to work the way I wanted it to.

I'll give the post a close look first thing in the morning.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] How to make the number in 'limit' => '1', a variable

By gkornbluth - September 27, 2010 - edited: September 27, 2010

Wow Chris,

Your solution worked like a charm.

I’ve modified the code to work with Dynamic Drive’s Thumbnail Viewer II, it looks really great and my client is much happier.

Two small questions.

1) In the page incrementing form, the<?php echo($photoPage + 1); ?> of “n” counter keeps incrementing each time the “next_message” link is clicked, regardless of the value of “n”.

I’ve tried to make the “next_message” and the “Submit” button disappear if the current page number is >= to “n” with no luck.

Here’s my current code for the form and other related code:

<?php
$photosPerPage = 5;
$photoPage = @$_REQUEST['photoPage'] ? $_REQUEST['photoPage'] - 1 : 0;
$firstIndex = $photoPage * $photosPerPage;
?>

<?php if ((ceil(sizeof($bookRecord['detail_page_images']) / $photosPerPage)) > 1): ?>

<form action="?num=<?php echo $bookRecord['num'] ?>" method="post">
<?php if ($firstIndex > 0): ?>
<a href="?photoPage=<?php echo $photoPage; ?>&=<?php echo $bookRecord['num'] ?>"><?php echo $common_informationRecord['previous_message'] ?></a>
<?php endif ?>

<span class="body-text-bold-9">Page <input type="text" name="photoPage" value="<?php echo($photoPage + 1); ?>" style="width: 25px;" /><input type="submit" value="Go" /> of <?php echo(ceil(sizeof($bookRecord['detail_page_images']) / $photosPerPage)); ?></span>

<?php if ($lastIndex < sizeof($bookRecord['detail_page_images']) - 1): ?>
<a href="?photoPage=<?php echo $photoPage+2; ?>&=<?php echo $bookRecord['num'] ?>"><?php echo $common_informationRecord['next_message'] ?></a><br />
<?php endif ?>
</form>

<?php endif ?>

<table border="0" cellspacing="3" cellpadding="3">
<tr>

<?php

if ($firstIndex > sizeof($bookRecord['detail_page_images'])-1 || $firstIndex < 0) { $firstIndex = 0; $photoPage = 0; }
$lastIndex = min($firstIndex + $photosPerPage, sizeof($bookRecord['detail_page_images'])) - 1;
foreach (range($firstIndex, $lastIndex) as $photoIndex):
$upload = $bookRecord['detail_page_images'][$photoIndex]
?>

<td align="left" valign="bottom">

<a href="<?php echo $upload['urlPath'] ?>" name="<?php echo $upload['thumbUrlPath2'] ?>""

rel="enlargeimage::mouseover::<br><?php $title = htmlspecialchars($bookRecord['title']); ?><span class=&quot;body-text-bold-9&quot;><?php echo ($title); ?></span><?php if ($bookRecord['condition']): ?><br /><?php $condition = htmlspecialchars($bookRecord['condition']); ?><span class=&quot;body-text-bold-9&quot;>Condition: </span><span class=&quot;body-text-bold-9&quot;> <?php echo ($condition); ?></span><?php endif; ?><?php if ($bookRecord['medium']): ?><br><?php $medium = htmlspecialchars($bookRecord['medium']); ?><span class=&quot;body-text-bold-9&quot;>Medium: </span><span class=&quot;body-text-9&quot;><?php echo ($medium); ?><?php endif; ?><?php if ($bookRecord['edition_size']): ?><br><?php $edition_size = htmlspecialchars($bookRecord['edition_size']); ?><span class=&quot;body-text-bold-9&quot;>Edition of: </span><span class=&quot;body-text-9&quot;><?php echo ($edition_size); ?></span><?php endif; ?>"

rev="loadarea" > <img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight']?>" border="0" style="margin-bottom: 5px" /> </a>

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


2) I’ve set up the Thumbnail Viewer II “loadarea“ (where the large images appear on rollover) so that the first image in the upload field appears as a default when the page is loaded.

Because of the way I’ve coded this, the same default image appears on the 2nd, 3rd, etc. page and I can’t seem to get the first image on that specific page to show instead.

Here’s the code snippet that loads the default image into the “loadarea”:

<?php foreach ($bookRecords as $record): ?>
<?php foreach ($record['detail_page_images'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath2'] ?>" alt="" border="0" /><?php break; ?>
<?php endforeach ?>

<?php endforeach ?>


A live sample page can be seen on the detail pages at:http://173.83.154.86/book.php

Any words of wisdom on either question?


Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [chris] How to make the number in 'limit' => '1', a variable

By gkornbluth - September 27, 2010 - edited: September 27, 2010

Well...

Seems like in my haste to clean up the incremental series of files that I was using for testing, I blew away the good ones and kept the really bad ones.

Sorry for wasting you time, Chris. I guess the "measure twice cut once" rule got me again.

Anyway, unless I'm embarrassed again, I think that it's all fixed now.

I did take your advice, added the 'allowSearch'=>false, and revised the default enlarged image code using $firstIndex as you suggested.

The "working" detail page is attached and I revised the code in the previous post to reflect the $bookRecord omission.

Thanks again,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

bookdetail.php 18K