display one picture on listing from array

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 9, 2013   (RSS)

Hi,

Is this on a detail page for a record? If so, you could display the first image in your image array using something like this:

<?php  
  // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  showme($blogRecords);

  $blog = $blogRecords[0];

?>
 
  <!-- display the first image in your array -->
  <?php if($image = @$blog['uploads'][0]): ?>
    <div>
      <img src="<?php echo $image['urlPath']; ?>" alt="<?php echo $image['info1']; ?>" />
    </div>
  <?php endif; ?>

This is just some example code, so you'll need to modify it to work with the variables you are using. I've left in my getRecords function so you can see how I've set it up. 

So if we can set the first images in the arrays data to the variable $image, then we we display the image. 

If you attach your code to a post, I could give you a more specific example if you need.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

thanks that did the trick!