Results 1 to 3 of 3

Thread: Omit duplicate/repeat entries from commentator list?

  1. #1
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Question Omit duplicate/repeat entries from commentator list?

    So before I ask my question...

    HEY EVERYONE, ANYBODY MISS ME?

    Ok, so yea. I'm back in biz now and ready to keep on learning.


    I'm not entirely sure if what I'm wanting to do should be done via the SQL query, or AFTER the query using PHP to filter the results...

    Here's a rundown of what the following code already does versus what I want it to do:

    The following code connects to the database that WP is installed in and accesses the "comments" table. It then makes a list of each person who has recently commented on the site (limit 16) and then runs their email address through a small snippet to verify whether or not they have set up an account with http://gravatar.com or not to determine what the alt/title text should read.

    The SQL query filters out my admin email address so that I am not listed in the list of commentators.

    All of this works perfectly. However, I need for it to also filter out any duplicate commentators from the list... In other words, if someone comments on the site more than once recently, it should only show their name in the list one time rather than XXX amount of times.

    You can see it at work here: http://sexybookmarks.net/#all

    Notice that there are several commentators who are listed more than once in the list... This is what I'm trying to get rid of.



    PHP Code:
    <?php
     
     
            
    global $wpdb;
            
    $comment_array $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' AND (comment_author_email <> '' AND comment_author_email <> 'my@admin_email_address.com') ORDER BY comment_date_gmt DESC LIMIT 16");
            
     
            
    $comment_total count($comment_array);
     
                    echo 
    '<ul>';
                    
                    for (
    $x 0$x $comment_total$x++) {
                            echo 
    '<li>';
                            
                            
                            
    // Craft a potential url and test its headers
                            
    $comment_email $comment_array[$x]->comment_author_email;
                            
    $hash md5($comment_email);
                            
    $uri 'http://www.gravatar.com/avatar/' $hash '?d=identicon&r=any&size=80';
                            
    $headers wp_get_http_headers($uri);
     
                            
    $getavatar get_avatar($comment_email);
     
                            
    // Check the headers
                            
    if (!is_array($headers)) {
                                    
    $has_valid_avatar FALSE;
                            }elseif (isset(
    $headers["content-disposition"]) ) {
                                    
    $has_valid_avatar TRUE;
                            }else {
                                    
    $has_valid_avatar FALSE;
                            }
     
                    if (
    $has_valid_avatar == "TRUE") {
                            
    $titletext $comment_array[$x]->comment_author;        
                    }
                    else {
                            
    $titletext $comment_array[$x]->comment_author." hasn't signed up for a Gravatar yet!";
                    }
     
                            echo 
    '<a href="'.$comment_array[$x]->comment_author_url.'" title="'.$titletext.'">';
                            echo 
    get_avatar($comment_array[$x]->comment_author_email65);
                            echo 
    '</a>';
                            echo 
    '</li>';
                    }
            echo 
    '</ul>';
    ?>
    Last edited by TheJoshMan; 08-03-2009 at 08:30 PM.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  2. #2
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    bump?
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  3. #3
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default Found it...

    Nevermind, I fond my own solution...



    Code:
    SELECT comment_author_email, comment_author, comment_author_URL, Max(comment_date_GMT)
     
    FROM $wpdb->comments
     
    where comment_approved = '1' AND (comment_author_email <> '' AND comment_author_email <> 'my@admin_email.com')
     
    Group By comment_author_email, comment_author, comment_author_URL
     
    ORDER BY Max(comment_date_gmt) DESC LIMIT 16
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •