Index: advpoll.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/advpoll.module,v
retrieving revision 1.21.2.85
diff -u -p -r1.21.2.85 advpoll.module
--- advpoll.module	8 Dec 2007 22:20:38 -0000	1.21.2.85
+++ advpoll.module	9 Dec 2007 19:05:19 -0000
@@ -1012,10 +1012,27 @@ function advpoll_votes_page() {
     $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
     $header[] = array('data' => t('Vote'), '');
 
-    $result = pager_query("SELECT v.value, v.uid, v.hostname, v.tag, u.name FROM {votingapi_vote} v LEFT JOIN {users} u ON v.uid = u.uid WHERE v.content_type = 'advpoll' AND v.content_id = %d". tablesort_sql($header), 20, 0, NULL, $node->nid);
+    $result = pager_query("SELECT v.uid, v.hostname, v.timestamp, u.name FROM {votingapi_vote} v LEFT JOIN {users} u ON v.uid = u.uid WHERE v.content_type = 'advpoll' AND v.content_id = %d GROUP BY v.uid, v.hostname, v.timestamp". tablesort_sql($header), 20, 0, NULL, $node->nid);
+    $uids = array();
+    $hostnames = array();
+    $timestamp = array();
+    $votes = array();
+    while ($vote = db_fetch_object($result)) {
+      $uids[$vote->uid] = $vote->uid;
+      $hostnames[$vote->hostname] = $vote->hostname;
+      $timestamps[$vote->timestamp] = $vote->timestamp;
+    }
+
+    // Need to handle this securely.
+    $uid_placeholders = array_fill(0, count($uids), '%d');
+    $host_placeholders = array_fill(0, count($hostnames), "'%s'");
+    $time_placeholders = array_fill(0, count($timestamps), '%d');
+    $query = "SELECT v.vote_id, v.tag, v.uid, v.hostname, v.timestamp, u.name FROM {votingapi_vote} v LEFT JOIN {users} u ON v.uid = u.uid WHERE v.content_id = %d AND v.uid IN(". implode(', ', $uid_placeholders) .") AND v.hostname IN(". implode(', ', $host_placeholders) .") AND v.timestamp IN(". implode(', ', $time_placeholders) .")". tablesort_sql($header);
+    $parameters = array_merge(array($query, $node->nid), array_values($uids), array_values($hostnames), array_values($timestamps));
+    $result = call_user_func_array('db_query', $parameters);
     $rows = array();
     while ($vote = db_fetch_object($result)) {
-      $key = $vote->uid ? $vote->uid : $vote->hostname;
+      $key = $vote->uid ? $vote->uid : $vote->hostname .'-'. $vote->timestamp;
       $rows[$key]['name'] = $vote->name ? theme('username', $vote) : check_plain($vote->hostname);
       if ($node->type == 'advpoll_ranking') {
         // Need two dimensional results (if equal rankings are allowed).
