Login | Sign up | Toll-Free: 1-800-752-0455



8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 21, 2017

I have this code with a little error, clic image link to see the error.


Please help me.

<?php foreach ($transparenciaRecords as $record): ?><?php if(!in_array(strtolower($record['a_o']), $alreadyListed)): ?><div class="block">
<div class="container">
<h2 class="block-title block-title--single">Transparencia <?php echo $record['a_o'] ?></h2>
</div><?php $alreadyListed[] = strtolower($record['a_o']); ?>
<?php endif; ?>
<div class="block">
<div class="container">
<!-- Wide table with range of cols -->
<div class="table-responsive">
<table class="table table-bordered table--wide table-present">
<colgroup class="col-sm-width">
</colgroup><colgroup class="col-sm-width">

<td><?php echo $record['a_o'] ?> - <?php echo $record['carpeta'] ?> - <?php echo $record['titulo'] ?></td>
<td><a class="btn btn-primary btn-sm" target="_blank" href="<?php foreach ($record['archivo'] as $upload): ?>
$extension = $upload['extension'];
if($extension == 'pdf' || $extension == 'rar') {
echo $upload['urlPath'];
} else {
echo "https://view.officeapps.live.com/op/view.aspx?"; echo $upload['filename'];
?><?php endforeach ?>">Ver Documento</a></td>
<?php endforeach ?>

Hi Alan, 

Try defining your array before your first foreach. eg: 

<?php $alreadyListed = []; ?>

That way it won't be undefined when you check if the first time.

Let me know if that works for you.

Dave Edis - Senior Developer

Thank you Dave this solved the Undefined variable error, but it still shows a 2016 record on 2015 records.


Can you try sorting by year in descending order? 

'orderBy' => 'a_o DESC, carpeta',

Let me know if that works for you.

Dave Edis - Senior Developer

Thank you Dave, I tested the code but the  sorting by year in descending order  I have the same problem.

  require_once "/lib/viewer_functions.php";
  list($transparenciaRecords, $transparenciaMetaData) = getRecords(array(
    'tableName'   => 'transparencia',
    'allowSearch' => '0',
    'orderBy' => 'a_o DESC, carpeta'

If you add this code just after that it will show debug output with the contents of $transparenciaRecords.

<?php showme($transparenciaRecords); ?>

Are the years in descending order in that output?  Also, can you confirm a_o is the year field? 

Dave Edis - Senior Developer

Hello Dave,

a_o  is the year field

I look that years are in descending order in that output.