Having uploads show in list veiwer

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 19, 2008   (RSS)

By Mohaukla - February 15, 2008

I have searched and have not found the exact answer so I will try my own post. I want to have included any uploaded files (PDF ect) in a list viewer instead of going to the page viewer to see them.

<?php
require_once "C:/Webspace/resadmin/mmoyers/efreewillmar.org/www/cmsAdmin/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'news_006'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = 'title'; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'news_006Page.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = ''; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'orderPriority+0 DESC, date DESC, title'; // (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);
?>
<?php foreach ($listRows as $record): ?>
<?php echo $record['content'] ?><br/>
<?php endforeach ?>

<?php if ($listDetails['noRecordsFound']): ?>
<span class="style21">This Content Is <br/>
Currently Unavailable.<br/>
Please Check Back Soon.</span><br/>
<?php endif ?>

<?php if ($record): ?>
<?php foreach (getUploads($options['tableName'], 'upload', $record['num']) as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" /><br/>
</span>
<?php else: ?>
<span class="style6"><br/><a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['info1'] ?></a><br/>
<br/>

<?php endif ?>
<?php endforeach ?>
<?php endif ?>

I am thinking that I need another "foreach" tag in the upload part of the code but I am not sure if thats what it will take or not.
Could you point me in the right direction?
Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] Having uploads show in list veiwer

By Dave - February 15, 2008

You're on the right track. Just copy and paste the block of code that displays uploads (from the page viewer) and past it _inside_ the foreach loop that displays your record.

So for your viewer that would be like this:

<?php foreach ($listRows as $record): ?>
<?php echo $record['content'] ?><br/>

Copy and paste upload display code here.

<?php endforeach ?>


Then it will display the uploads or attachments for each record.

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

Re: [justritedesign] Having uploads show in list veiwer

By Dave - March 19, 2008

You bet, PHP has a function for "breaking" out of a foreach loop called 'break'. Also, if you're never going to have anything but thumbnails you can remove the code that shows download links (keep it if you need it). Try this:

<?php foreach (getUploads($options['tableName'], 'uploads', $record['num']) as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" onmousedown="MM_swapImage('picture','','<?php echo $upload['urlPath'] ?>',1)" />
<!-- <span class="t12_white"><?php echo $upload['info1'] ?></span><br />-->
<?php break; ?>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['info1'] ?></a><br/>
<?php endif ?>
<?php endforeach ?>


Basically, it won't see the break() code until the first time it shows a thumbnail, then it will "break" out of the loop and won't show anything else. You can use break() in any foreach loops when you want to show just one of something.

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