Filtering out Certain Records

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

Hi there, I need to filter out certain records which match:

suppress=1

from the following code, any suggestions on how I would do this?

<?php
$values = getListValues('yachts','destinations',$record['destinations']);
$labels = getListLabels('yachts','destinations',$record['destinations']);
$valuesToLabels = array_combine($values, $labels);
?>
<p class="destinations">Destinations: <br />
<?php $count2=0; ?>
<?php foreach ($valuesToLabels as $value => $label): ?>
<?php echo ($count2==0)? "" : ", " ?>
<a href="/destination.php/<?php echo str_replace(" ","-",strtolower($label."-".$value)); ?>/"><?php echo htmlspecialchars($label); ?></a>
<?php $count2++;?>
<?php endforeach ?>
</p>


Many thanks
Jan

Re: [aquaman] Filtering out Certain Records

By Jason - September 21, 2010

Hi Jan,

In which table would the field suppress appear? Do you need to remove those records from the entire page, or just from this one section of code?

If you could attach your entire .php page, I can take a closer look into the issue for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [aquaman] Filtering out Certain Records

By Jason - September 21, 2010

Hi Jan,

Since we're not actually selecting records from the destinations table, try this code (I've highlighted the changes in red):

<?php foreach ($valuesToLabels as $value => $label): ?>
<?php
$where ="num =".intval($value)." AND suppress=1";
if(mysql_select_count_from('destinations',$where)){
continue;
}
?>

<?php echo ($count2==0)? "" : ", " ?><a href="/destination.php/<?php echo str_replace(" ","-",strtolower($label."-".$value)); ?>/"><?php echo htmlspecialchars($label); ?></a>
<?php $count2++;?>
<?php endforeach ?>


This code assumes that the table is called "destinations". If not, you'll need to change the code to reflect that. What this is doing is for each destination number in the array, it checks if that record has suppress set to 1. If it does, it skips to the next record in the list.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Filtering out Certain Records

Perfect, thanks Jason!