Photo/Image of the day

18 posts by 2 authors in: Forums > CMS Builder
Last Post: October 7, 2008   (RSS)

By grauchut - September 18, 2008 - edited: September 18, 2008

Dave I got the random to work. Here is what code I have. It works great but I want it to limit to just showing one picture. How can I make that happen. Thanks

<?php
require_once "/webroot/e/m/test/test/www/cmsAdmin/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'index'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = ''; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = ''; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = '1'; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'RAND()'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$options['pageNum'] = ''; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
$options['where'] = ''; // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
$options['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
list($listRows, $listDetails) = getListRows($options);
?></span>
<div align="left"><span class="style43">
<?php foreach ($listRows as $record): ?>
</span>
<!-- /STEP1: Load Record List -->
<!-- STEP2: Display Record List (Paste this where you want your records to be listed) -->
<table width="55" align="center">
<tr>
<td width="47" valign="top"><div align="center">
<!-- STEP3: Display Uploads from 'main_images' (Paste this where you want your uploads displayed) -->
<!-- Upload Program Fields : num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath -->
<!-- Upload Image Fields : isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight -->
<!-- Upload Info Fields : info1, info2, info3, info4, info5 -->
<?php foreach (getUploads($options['tableName'], 'main_images', $record['num']) as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<table border="1" bordercolor="#00003E">
<tr>
<td><a href="<?php echo $record['_link'] ?>"><strong><img src="<?php echo $upload['thumbUrlPath'] ?>" width="150" height="150" border="0" /></strong></a><a href="<?php echo $record['_link'] ?>"><strong></strong></a></td>
</tr>
</table>
<br/>
<?php elseif ($upload['isImage']): ?>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['filename'] ?></a><br/>
<?php endif ?>
<?php endforeach ?>
<!-- STEP3: /Display Uploads from 'main_images' -->
</div></td>
</tr>
</table>
</div>
<div align="left">
<?php endforeach ?>
<?php if (empty($listRows)): ?>
<!-- Display "No Records Found" Message -->
No records were found!<br/>
<br/>
<?php endif ?>
Glenn Rauchut (Owner) Emergency Designz

Re: [grauchut] Photo/Image of the day

By Dave - September 19, 2008

Hi Glenn,

Try this near the bottom of the upload loop:

...
<?php elseif ($upload['isImage']): ?>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['filename'] ?></a><br/>
<?php endif ?>
<?php break ?>
<?php endforeach ?>
<!-- STEP3: /Display Uploads from 'main_images' -->


That will tell it to stop after one "loop" or image shown.

Let me know if that does the trick for you.
Dave Edis - Senior Developer
interactivetools.com

By grauchut - September 20, 2008

Dave,

It works great. One Question. If I reference to the main index images. I noticed if there isn't a picture associated with the entry it doesn't show a picture. Is there a trick to make it skip ones without photos. Thanks Glenn
Glenn Rauchut (Owner) Emergency Designz

Re: [grauchut] Photo/Image of the day

By Dave - September 22, 2008

There's no easy way to do that because the photo data is stored in a different table.

One thing you could do is have a checkbox called "Include in Photos of the Day" and only check that for records you wanted included (which of course would have photos).

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

By grauchut - September 22, 2008

Would this be set up like the feature check box?
Glenn Rauchut (Owner) Emergency Designz

Re: [grauchut] Photo/Image of the day

By Dave - September 22, 2008

Yes, exactly! Except with a different name.

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

By grauchut - October 7, 2008

Dave, I added a checkbox for the image to be added. How do I add it into the coding.

<?php
require_once "/webroot/1/2/1212121/1121212/www/cmsAdmin/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'index'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = ''; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'indexPage.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = '1'; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'RAND()'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';[/#ff0000]
$options['pageNum'] = ''; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
$options['where'] = ''; // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
$options['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
list($listRows, $listDetails) = getListRows($options);
?>

Image Of The Day: <?php echo $record['image_of_the_day'] ?>

Thanks Glenn
Glenn Rauchut (Owner) Emergency Designz