Find records with upload and Distinct
            2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 10, 2015   (RSS)          
Hi there,
We'd like to pull a list of records where the client has uploaded an image into an upload-type field. Not all records in the table have an upload. Further, we'd like to pull only a single record from each category type (another field).
Can anyone suggest a query which would pull a random record from each category of product but only select ones which have an image uploaded? Am assuming that a 'groupBy' parameter is involved but I can't seem to make this work in my trials.
Many thanks,
Jayme
By gkornbluth - June 10, 2015
Hi Jayme,
Don't know if this will help.
I use the following to show a single image on a page only if there are images uploaded to the images field in the member's account record on site pages, and to display another image when the page is re-loadeds.
You'll have to get rid of the code that displays image titles and the member's name.
You can see working pages at http://www.nawafl.com/
Hope that gets you started in a usable direction
Best,
Jerry Kornbluth
<?php
   $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/path_to_you_server/','','../','../../','../../../');
   foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
   if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
   ?>
 <?php $uploadRecords = mysql_select('uploads', " tableName = 'accounts' AND fieldName = 'images'"); // Load Images From Records With 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;">
         <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: #<?php echo $nawa_colorsRecord['rotator_artist_s_name_and_title_color'] ?>;" class="shadow1">
           <?php if ($upload['info1']):?>
           <?php echo ucwords($upload['info1']); ?>
           <?php // else :?>
           <?php // echo $upload['urlPath']; ?>
           <?php endif?>
         </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: #<?php echo $nawa_colorsRecord['rotator_artist_s_name_and_title_color'] ?>;" class="shadow1">
           <?php  echo $record2['first_name']; ?>
           <?php echo $record2['last_name']; ?> </div>
         <?php endforeach ?>
       </div></td>
   </tr>
 </table>
 <?php break?>
 <?php endforeach ?>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php