Remove duplicate entries from views results... the hard way.
User login
Tuesday, October 25, 2011 - 22:27
In some cases it is seems impossible to get rid of the duplicate entries that views return in the output.
Not an elegant way, but this small module would do the trick...
So let's create a module the usual way, and put the following code in the .module file.
This one is called remove_duplicates.
<?php
function <MY_MODULE>_views_pre_render(&$view)
{
$used_nids = array();
foreach ($view->result as $row)
{
if (!in_array($row->nid, $used_nids))
{
$new_view_result[] = $row;
$used_nids[] = $row->nid;
}
}
$view->result = $new_view_result;
}
?>
Tags:
Drupal 6, Drupal 7, Drupal Quick Tips, Views