Current and Archive lists on the same page

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 25, 2013   (RSS)

By gregThomas - July 24, 2013

Hi, what about doing two different getRecords calls with a where statement that retrieves the current and archive checked records only?

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/test/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records from 'blog'
  list($currentRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'babington_bulletin',
    'loadUploads' => true,
    'allowSearch' => false,
    'where'       => "`current` = 1",
  ));

    // load records from 'blog'
  list($archiveRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'babington_bulletin',
    'loadUploads' => true,
    'allowSearch' => false,
    'where'       => "`archive` = 1",
  ));

This is just example code, so you might have to make a few changes to get it working with your page.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By MercerDesign - July 25, 2013

Ok, but how do I get the 2 lists to display separately, current in one area and archive in another, it seems I need to put a where statement or something on the actual page where the content displays.

By gregThomas - July 25, 2013

Hi, 

You would need to use two seperate foreach loops to pass through both arrays in the two locations where you want the records to display:

<div style="float:left">
  <!-- display records from first table -->
  <ul>
    <?php foreach($currentRecords as $record): ?>
      <li><?php echo $record['title']; ?></li>
    <?php endforeach; ?>
  </ul>
</div>
<div style="float:left">
  <!-- display records from second table -->
  <ul>
    <?php foreach($archiveRecords as $record): ?>
      <li><?php echo $record['title']; ?></li>
    <?php endforeach; ?>
  </ul>
</div>

This is just example code, so you'll need to modify it to work with your website.

So I've created two separate foreach loops to pass through the currentRecords and archiveRecord arrays separately. This way you can cycle through each loop where ever you want on your page.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com