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

By gkornbluth - September 26, 2010

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: [gkornbluth] How to make the number in 'limit' => '1', a variable

By Chris - September 27, 2010

Hi Jerry,

1) You'll need to assign a value to $lastIndex before you try to use it in the IF block.

2) To do this, you won't need any foreaches at all. Instead, you can refer to the specific upload using $firstIndex as the index:

<?php $upload = $bookRecord['detail_page_images'][$firstIndex] ?>
<img src="<?php echo $upload['thumbUrlPath2'] ?>"...


Two other things I noticed:

3) You'll want to add 'allowSearch'=>false to your common_information getRecords call. When you click "Go" on your page selector, the URL becomes "num=7", and the common_information gerRecords call is trying to filter on that, which is why the background colour blanks out, etc.

4) There are a bunch of PHP errors (more if you view source) related to using the variable $record before it's defined (I think you want to use $bookRecord instead.)

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

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