Duplicate Items from a for each array

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

By Dave - September 5, 2017

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
interactivetools.com

By AlanAlonso - September 5, 2017

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

http://preview.ibb.co/b3vQWv/Ashampoo_Snap_2017_09_05_22h35m06s_001.png

By Dave - September 6, 2017

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
interactivetools.com

By AlanAlonso - September 6, 2017

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

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

By Dave - September 11, 2017

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
interactivetools.com

By AlanAlonso - September 20, 2017

Hello Dave,

a_o  is the year field

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

By Dave - September 21, 2017

Hmm, I'm not sure.  You could try outputting each record in your foreach loop as well to see if the order is getting changed somehow:

<?php foreach ($transparenciaRecords as $record): ?>
  <?php showme($record); ?>

And also view-source on the page and make sure the HTML itself is in the right order and it's not just a display issue.  Other than that we'd need to spend some time and debug it to know.  The code looks good from as far as I can tell.  Let me know what you find!

Dave Edis - Senior Developer
interactivetools.com