Skip duplicate records

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

By leo - June 7, 2018

Hi Hiroko,

If you want to get related artist/event records from an event record, you don't need massive nested foreach loops to do that. You can get the records you need by using mysql_select or getRecords with where statements when you are looping through artist nums.

Regarding the duplicate record issue, you can try creating an array of record nums first and add new num when the num doesn't already exist in the array, and then get all the records once in the end. Here is an example showing the concept:

...

$eventNumArray = [];

...
// When you figured the event that needs to be displayed
if(!in_array($eventRecord['num'], $eventNumArray)){
  $eventNumArray[] = $eventRecord['num'];
}

...
$displayEventRecords = mysql_select('events', 'num IN (' . implode(',', $eventNumArray) . ')');

foreach($displayEventRecords as $record){
 // echo html to show the related event record
}

Let me know if you have any questions!

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

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