Image Rotator Question

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

Hey Jerry,

I just want to make sure I understand. So in the second block you'd like to modify the $uploadRecords that are loaded, so that they only retrieve records that are loaded in the first block?

Does the first block display more than one record? It looks like this code:

 if (@$alreadySeen[ $record[''] ]++) { continue; }

would return true or false every time, so I'm guessing the for each loop through all of the returned records each time?

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - January 2, 2015 - edited: January 2, 2015

Hi Greg,

Thanks for looking at this and happy new year.

I want modify the second block of code to:

1) Only load the records with upload fields that contain images (which it does now) and

2) Allow me to pull the name fields (first_name and last_name) from the parent record of that particular upload field.

So that the end result is that I can display one random record and image from among the records that contain images, and embed both the name of the artist and the adjusted image file name in that displayed image.

You can see a working example of the first code block at http://50.87.248.95/~nawaflco/nawafl/about.php and the current second block at http://50.87.248.95/~nawaflco/nawafl/about2.php

Hope that makes more sense...

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

Hi Jerry,

Happy new year! I think I see what you're trying to do, so the first name and last name aren't matching the retrieved image? I've modified the second code block to retrieve the user details of the image uploader:

<?php $uploadRecords = mysql_select('uploads', " tableName = 'accounts' AND fieldName = 'images'"); ?>
<table align="center" width="80%" border="0" cellpadding="5">
  <tr>
    <?php shuffle($uploadRecords) ?>
    <?php foreach ($uploadRecords as $upload): ?>
    <td align="center">
      <div onclick='window.location="#"' class="round-corner" style="position: relative; background: url(<?php echo $masterurl ?>/cmsAdmin/uploads/<?php echo
$upload['thumbUrlPath2'] ?>); width: <?php echo $upload['thumbWidth2'] ?>px; height: <?php echo $upload['thumbHeight2']
?>px;">
      <?php
      
        $upload['urlPath'] = preg_replace('/\.\w+$/', '', $upload['urlPath']); 
        $upload['urlPath'] = preg_replace("/[-_]/", " ", $upload['urlPath'] ); 
        $upload['urlPath'] = ucwords($upload['urlPath'] ); 

      ?>
        <div style="position: absolute; top: .9em; left: 1.2em; width: 200px; font-family:Verdana, Tahoma, Arial, Sans-Serif; font-size:1.2em; font-weight:bold; text-align:left; font-style: normal; color: #00F;" class="shadow1">
          <?php echo $upload['urlPath']; ?>
        </div>
        <?php  
          list($accountsRecords, $accountsMetaData) = getRecords(array(
          'tableName'   => 'accounts',
          'where'       => "`num` = '{$upload['recordNum']}'"
          'loadUploads' => false,
          'allowSearch' => false,
          'limit'       => '1',
        ));
        ?>
        <?php foreach ($accountsRecords as $record2): ?>
          <div style="position: absolute; bottom: 1.2em; left: 1.2em; width: 200px; font-family:Verdana, Tahoma, Arial, Sans-Serif; font-size:1.2em; font-weight:bold; text-align:left; font-style: normal; color: #00F;" class="shadow1">
            <?php  echo $record2['first_name']; ?> <?php echo $record2['last_name']; ?>
          </div>
        <?php endforeach ?>
      </div>
    </td>
  </tr>
</table>
<?php break?>
<?php endforeach ?>

So the code above will only retrieve one record, which should speed up the page load times as not all of the records are being retrieved. I've also added a where statement that will retrieve the account record based on the upload record chosen, as the upload section stores the record number value in a field called recordNum. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Thanks Greg,

I'd forgotten about the $upload['recordNum']

It now works extremely well and I'll add this recipe to the CMSBCookbook.

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