Skip duplicate records

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 20, 2018   (RSS)

By hiroko - June 7, 2018

Hi,

I have an exhibition detail viewer page where the participating artists are listed. In this page, I have a list of related exhibition but I am having a problem with duplicate records listed when the artists are participating in the same exhibitions.

This is the listing part of the detail page.

<!--Related exhibitions-->
        <div class="l-column l-row u-paddingTop--half">
            <?php $fieldValues = explode("\t",trim($detailRecord['this_artist'],"\t")); ?>
            <?php foreach($fieldValues as $artistNum): ?>
            <?php foreach ($eventRecords as $record): ?>
            <?php $fieldValues2 = explode("\t",trim($record['this_artist'],"\t")); ?>
            <?php foreach($fieldValues2 as $artistNum2): ?>
            <?php if ($artistNum2 == $artistNum && ($artistNum > 0)): ?>
            <div class="EntryPanel l-flexAuto-4column">
                <div class="EntryPanel--vertical">
                    <a href="/en/<?php echo $record['permalink'] ?>/" title="<?php echo $record['title'] ?>">
                        <div class="EntryPanel__sub EntryPanel__sub--medium imgLiquidFill imgLiquid">
                            <?php foreach ($record['image'] as $index => $upload): ?>
                            <?php if ($index >= 1) { continue; } // limit uploads shown ?>
                            <img src="<?php echo htmlencode($upload['thumbUrlPath2']) ?>" alt="<?php echo $record['num'] ?><?php echo $record['title'] ?>"/>
                            <?php endforeach ?>
                        </div>
                    </a>
                    <div class="EntryPanel__main">
                        <a href="/en/<?php echo $record['permalink'] ?>/" title="<?php echo $record['title'] ?>">
                            <h3 class="EntryPanel__head">
                                <?php echo $record['title'] ?>
                            </h3>
                        </a>
                    </div>
                </div>
            </div>
            <?php endif ?>
            <?php endforeach ?>
            <?php endforeach ?>
            <?php endforeach ?>
            <!--/Related Exhibitions-->

Is there a way to skip the same records?

This is the example of the page. The list is at the bottom page.

Thank you in advance.

Hiroko

By hiroko - June 20, 2018

Hi Leo,

Thanks for the reply and sorry for the late response.

I couldn't figure out how to get the related records from a multi value field for a while, but looking through the forum, I am finally getting the result I need.

I tried some options, and this post seemed to fit:

https://www.interactivetools.com/forum/forum-posts.php?Display-select-uploads-from-one-category-on-another-category-page-using-pulldown-multi-value-list-81068

In my case the code became like this

if(is_array(@$detailRecord['this_artist:values'])){
    $arrayCounter = count($detailRecord['this_artist:values']);
    foreach($detailRecord['this_artist:values'] as $key => $filterItem){
        $searchString .= "this_artist LIKE '%\t$filterItem\t%'";
        if(($key+1) != $arrayCounter){
            $searchString .= " OR ";
        }
    }  
}

this worked except the viewer shows all records when there is nothing selected on the multi value.

So, I used a non-existing num to avoid it. ( I am sure there is a better solution to this )

$searchString = '';
if(!@$detailRecord['this_artist']){
    $searchString .= "this_artist LIKE '%\t0\t%'";
}
if(is_array(@$detailRecord['this_artist:values'])){
    $arrayCounter = count($detailRecord['this_artist:values']);
    foreach($detailRecord['this_artist:values'] as $key => $filterItem){
        $searchString .= "this_artist LIKE '%\t$filterItem\t%'";
        if(($key+1) != $arrayCounter){
            $searchString .= " OR ";
        }
    }  
}

Will this cause any problem?

By leo - June 20, 2018

Hi Hiroko,

That looks good to me!

Leo - PHP Programmer (in training)
interactivetools.com