Display Certain Records

5 posts by 2 authors in: Forums > CMS Builder
Last Post: October 6, 2012   (RSS)

By shawnpatoka - October 5, 2012

So i have a bunch of records with check boxes, either "Participating Bar" or "Not Participating Bar". How do I show only the records that have the "Participating Bar" checked?

Thanks!

Re: [shawnpatoka] Display Certain Records

By gregThomas - October 5, 2012

Hi,

You can use a get Records function to filter them out fairly easily.

I would do something like this:

list($barRecords, $barMetaData) = getRecords(array(
'tableName' => 'barSection',
'loadUploads' => true,
'allowSearch' => false,
'where' => "participatingBarField = '1'"
));


If you change the names of the field and section in the example above, it should output only bars that are participating.

A tick box value is stored as 1 for ticked and 0 for unticked in CMS Builder.

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [shawnpatoka] Display Certain Records

By gregThomas - October 5, 2012

To keep things simple I would make two getRecords requests, one for bars who are participating and one for any which aren't, then loop through both of them individually.

Something like this should work:

<?php

list($participating, $barMetaData) = getRecords(array(
'tableName' => 'barSection',
'loadUploads' => true,
'allowSearch' => false,
'where' => "participatingBarField = '1'"
));

list($notParticipating, $barMetaData) = getRecords(array(
'tableName' => 'barSection',
'loadUploads' => true,
'allowSearch' => false,
'where' => "participatingBarField = '0'"
));
?>


<?php foreach($participating as $row): ?>
<p><?php echo $row['title']; ?></p>
<a href="detailsPage.php?num=<?php echo $row['num'];?>" ><?php echo $row['title']; ?></a>
<?php endforeach; ?>

<?php foreach($notParticipating as $row): ?>
<p><?php echo $row['title']; ?></p>
<?php endforeach; ?>


You'll need to change fields, file names and sections so that they are applicable to your example.

Let me know if this doesn't work.

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Display Certain Records

By shawnpatoka - October 6, 2012

thank you very much, it worked great!