Current and Archive lists on the same page

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

I have got a Multi List that is going to display bulletins, I need it to display a current issue and then archived issues on the same page but in different lists, I have created 2 check boxes: Current and Archive, the table name is babington_bulletin, but I cannot get the 2 lists to display. Please can anyone help.

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 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