Variable not being passed when paging

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 6, 2015   (RSS)

Hi all,

Another small issue that I could use some help with.

I have an upload field in my accounts section that accepts multiple images and I’m populating a viewer with those images when a visitor clicks on a “view the members images” link. I'm using a previous and next page link scenario to limit the number of thumbnails shown on a page.

On my list page I’m adding the account record number to the URL with:

<a href="artistsa.php?member_num=<?php echo $record['num'] ?>">Click/Tap To See <?php echo $record['first_name'] ?>'s Member Page</a>

And on the member image viewer I’m using this code to show the thumbnails and a larger image:

<?php //  $recnum = $_REQUEST['member_num']; // load $recnum from end of url ?>
<?php
 $maxImages = 10;
 $maxCol = 5;
$recnum = 586; // hard code the $recnum variable
 list($accountsRecords, $accountsMetaData) = getRecords(array(
    'tableName'   => 'accounts',
   'where'       => "`num` = $recnum",
    'loadUploads' => true,
    'allowSearch' => true,
    'limit'       => '1',
    'debugSql' => true,
  ));
  $accountsRecord = @$accountsRecords[0]; // get first record

?>

<table width="80%" border="0" align="center">
  <tr>
    <td valign="top">

<?php
$photosPerPage = $maxImages;
$photoPage = @$_REQUEST['photoPage'] ? $_REQUEST['photoPage'] - 1 : 0;
$firstIndex = $photoPage * $photosPerPage;
$lastIndex = min($firstIndex + $photosPerPage, sizeof($accountsRecord['images'])) - 1;
?>
      <?php if ((ceil(sizeof($accountsRecord['images']) / $photosPerPage)) > 1): ?><form action="?num=<?php echo $accountsRecord['num'] ?>" method="post">
        <?php if ($firstIndex > 0): ?>
        <a href="?photoPage=<?php echo $photoPage; ?>&=<?php echo $accountsRecord['num'] ?>"><span
class="text_font">Click/Tap For Previous Page</span></a>   
        <?php endif ?>
        <span class="text_font" >Page
        <input type="text" name="photoPage" value="<?php echo($photoPage + 1); ?>" class="text_font" style="background-color:transparent; width:
10px; border:hidden;" />
        of <?php echo(ceil(sizeof($accountsRecord['images']) / $photosPerPage)); ?></span>
        <?php if ($lastIndex < sizeof($accountsRecord['images']) - 1): ?>
        <input style="background-color:transparent; border:hidden;" type="submit" value="" />
        <a href="?photoPage=<?php echo $photoPage+2; ?>&=<?php echo $accountsRecord['num'] ?>"><span
class="text_font">Click/Tap For Next Page</span></a><br />
        <?php endif ?>
      </form>
      <?php endif ?>
      <br />
      <table border="0" cellspacing="3" cellpadding="3" width="80%">
        <tr>
          <?php

if ($firstIndex > sizeof($accountsRecord['images'])-1 || $firstIndex < 0) { $firstIndex = 0; $photoPage = 0; }

foreach (range($firstIndex, $lastIndex) as $photoIndex):
@$upload = $accountsRecord['images'][$photoIndex]
?>
          <td align="center" valign="middle"><a title="<span class=&quot;text_font&quot;><br /> <?php echo
htmlspecialchars($upload['info1']); ?> <?php echo htmlspecialchars($upload['info2']); ?> <?php echo
htmlspecialchars($upload['info3']); ?><br /> </span>" href="<?php echo $upload['thumbUrlPath2'] ?>"

rel="enlargeimage" rev="targetdiv:loadarea," > <img class="round-corner" src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo
$upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight']?>" border="0" style="margin: 5px" /> </a></td>
          <?php $maxCol; if (@++$count % $maxCol == 0): ?>
        </tr>
        <tr>
          <?php endif; ?>
          <?php endforeach ?>
        </tr>
      </table>
</td>
        </tr>
      </table>
      <table align="center" border="0" cellpadding="5" cellspacing="0" width="80%">
        <tr>
          <td align="center" valign="top" >
            <div align="center" id="loadarea" style="width: 650px; height: 500px;">
              <?php $upload = @$accountsRecord['images'][$firstIndex] ?>
              <span class="text_font"><br />
              <?php echo htmlspecialchars($upload['info1']); ?> <?php echo htmlspecialchars($upload['info2']); ?> <?php
echo htmlspecialchars($upload['info3']); ?></span> <br />
              
              <img class="round-corner" src="<?php echo $upload['thumbUrlPath2'] ?>" alt="" border="0" /><br />
            </div></td>
        </tr>
      </table>

When I hard code the $renum variable, all of the pages page through as they should, the num variable is passed to each page and debug reports the same for all pages:

SELECT SQL_CALC_FOUND_ROWS `accounts`.* FROM `cms_accounts` as `accounts` WHERE (`num` = 586) AND `accounts`.hidden = 0 ORDER BY hidden, last_name, username LIMIT 1
tableName = 'accounts' AND fieldName IN ('images') AND recordNum IN (586) ORDER BY `order`, num

When I pass the $recnum variable using the URL, only the first page of images shows correctly. The others throw a mysql error:

 MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND `accounts`.hidden = 0 ORDER BY hidden, last_name, username LIMIT 1' at line 3

And debug show:

SELECT SQL_CALC_FOUND_ROWS `accounts`.* FROM `cms_accounts` as `accounts` WHERE (`num` = ) AND `accounts`.hidden = 0 ORDER BY hidden, last_name, username LIMIT 1.

It seems the record number is not being passed along to the additional pages and I don’t know why or how to fix it.

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

By claire - January 6, 2015

Hey Jerry, looks like you're missing the member_num in the paging links. Try this code:

 <?php if ((ceil(sizeof($accountsRecord['images']) / $photosPerPage)) > 1): ?><form action="?num=<?php echo $accountsRecord['num'] ?>" method="post"> 
        <?php if ($firstIndex > 0): ?>
        <a href="?photoPage=<?php echo $photoPage; ?>&member_num=<?php echo $accountsRecord['num'] ?>"><span
class="text_font">Click/Tap For Previous Page</span></a>   
        <?php endif ?>
        <span class="text_font" >Page
        <input type="text" name="photoPage" value="<?php echo($photoPage + 1); ?>" class="text_font" style="background-color:transparent; width:
10px; border:hidden;" />
        of <?php echo(ceil(sizeof($accountsRecord['images']) / $photosPerPage)); ?></span>
        <?php if ($lastIndex < sizeof($accountsRecord['images']) - 1): ?>
        <input style="background-color:transparent; border:hidden;" type="submit" value="" />
        <a href="?photoPage=<?php echo $photoPage+2; ?>&member_num=<?php echo $accountsRecord['num'] ?>"><span
class="text_font">Click/Tap For Next Page</span></a><br /> 
        <?php endif ?>
      </form>
      <?php endif ?>
      <br /> 
      <table border="0" cellspacing="3" cellpadding="3" width="80%">
        <tr>

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/