Image uploads - count + display

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

By Deborah - May 27, 2013

Hi.

I'd like to display on a list page the count and total number of images for a record's multiple-upload field.

Example: "Image 2 of 4"

I'm not able to find an example here in the forum. I've used 'count' functions in connection with records before, but not with uploads within a record.

Thanks for any help!

~ Deborah

By Daryl - May 28, 2013 - edited: May 28, 2013

Hi Deborah,

All the uploaded files are stored in the  "uploads" table and is associated by its "tableName" and "recordNum" fields with all of the other tables' table name and "num" field of its record.

Example:


$getImageCount = count(mysql_select('uploads', array('tableName' => 'products', 'recordNum' => '1')));
echo $getImageCount;
// wherein 'recordNum' => '1', '1' is the 'num' field of a record inside the 'products' table

Or if you're using the getRecords function, the uploads data are stored in ['images'] field: 

  // load records from 'products'
  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'loadUploads' => true,
    'allowSearch' => false,
  ));
  
  foreach ($productsRecords as $record){
    echo count($record['images']);
  }

Hope this helps!

Regards,

Daryl

Daryl Maximo
PHP Programmer - interactivetools.com