PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Get Leads and remove duplicates for displaying on front end

  1. Hello -

    I am trying to display my form entries on the front end like so: (partially finished) http://cl.ly/0D3u2y2G2E3s3m2n1B1z

    You will see the filters there. I am currently doing this to get them to show up:

    $restaurant = RGFormsModel::get_leads(1, '8', 'ASC', '', '0', '99999999');
    $restaurant_2 = RGFormsModel::get_leads(3, '8', 'ASC', '', '0', '99999999');
    $rests = array_merge($restaurant, $restaurant_2);
    
    foreach($rests as $rest) {
    if(!empty($rest['8'])) :
    $html = $rest['8'];
    endif;
    }
    return $html;

    This works fine, even with the array merge. However, it is showing duplicated items. I want to only show one result if there are duplicates. I have tried this using array_unique:

    $restaurant = RGFormsModel::get_leads(1, '8', 'ASC', '', '0', '99999999');
    $restaurant_2 = RGFormsModel::get_leads(3, '8', 'ASC', '', '0', '99999999');
    $rests = array_merge($restaurant, $restaurant_2);
    
    foreach(array_unique($rests) as $rest) {
    if(!empty($rest['8'])) :
    $html = $rest['8'];
    endif;
    }
    return $html;

    However, it stops after the first item like so:

    http://cl.ly/1U3S2Y023W2D162X3538

    Any thoughts here on how to get this to work. I am trying to use these a filtering navigation, so I really just need the single item, not the duplicates.

    Posted 12 years ago on Friday April 27, 2012 | Permalink
  2. David Peralty

    Can you try to do the array_unique call before the foreach and see if that solves your issue.
    Something like:

    $unique_rests = array_unique($rests);

    I'm no sure why it isn't working, but I want to reduce the chance that it has to do with doing the array_unique inside the foreach.

    Posted 12 years ago on Friday April 27, 2012 | Permalink
  3. Sadly, that produces the same issue with it stopping after one item.

    Posted 12 years ago on Friday April 27, 2012 | Permalink
  4. David Peralty

    I'm really not sure why having the unique call would stop the foreach from going through all the values.

    Could you print the rests array to a text file so we can take a look at it? Maybe even print the unique rests to a text file as well. Maybe the unique call isn't doing what it should for some unknown reason.

    Posted 12 years ago on Friday April 27, 2012 | Permalink
  5. array_unique() is not intended to be used with multi-dimension array, so I think that is where the unexpected behavior is coming from. Before calling array_unique(), try creating converting your $rests array into an array of strings instead.

    Posted 12 years ago on Monday April 30, 2012 | Permalink
  6. Thanks Alex -

    not entirely sure how to handle that. But here are my Text files of the array merge and then the array unique.

    http://cl.ly/0d0R331O3u3t2k272v3a

    I just used var_dump to show these.

    Posted 12 years ago on Monday April 30, 2012 | Permalink
  7. Let me just clarify something so that I can give you a working code snippet. Do you just want to display the names of the the restaurant, or are you going to display any other information associated with them?

    Posted 12 years ago on Monday April 30, 2012 | Permalink
  8. I would like to just show the names of the restaurants. I already have working code to show all of the people that have signed up. For the people it is okay to have duplicates because they will be signing up for multiple restaurants.

    Posted 12 years ago on Tuesday May 1, 2012 | Permalink
  9. You will probably need to change the way they are formatted, but I think the following snippet will point you in the right direction.

    $restaurant = RGFormsModel::get_leads(1, '8', 'ASC', '', '0', '99999999');
        $restaurant_2 = RGFormsModel::get_leads(3, '8', 'ASC', '', '0', '99999999');
        $rests = array_merge($restaurant, $restaurant_2);
    
        $html = "";
        //creating unique array of restaurant names
        $names = array();
        foreach($rests as $rest) {
            $name = $rest['8'];
            if(!empty($name) && !in_array($name, $names)){
                $names[] = $name;
                $html .= $name . " ";
            }
        }
    
        return $html;
    Posted 12 years ago on Tuesday May 1, 2012 | Permalink
  10. Awesome. Works perfectly! Thank you so much. I really appreciate it.

    Posted 12 years ago on Wednesday May 2, 2012 | Permalink
  11. Alex is the man! Glad you are rolling.

    Posted 12 years ago on Wednesday May 2, 2012 | Permalink

This topic has been resolved and has been closed to new replies.