Community Documentation

Paypal blocks

Last updated May 29, 2007. Created by bertboerland on February 10, 2005.
Edited by add1sun, puregin, robertDouglass, bryan kennedy. Log in to edit this page.

Here are two snippets that display how much and who has made donations. Requires the paypal_framework module.

Total money sent to you:

<?php
$result
= db_query("
    SELECT SUM(payment_gross) as total FROM paypal_log
  "
);
 
$pp = db_fetch_object($result);
  print
sprintf( "%01.2f", $pp->total+0 );
?>

The 10 most recent people to have sent you the money:

<?php
$result
= db_query("
    SELECT business,option_name1 FROM paypal_log ORDER BY payment_date DESC LIMIT 10
  "
);
 
$count = 0;
  while(
$donor = db_fetch_object($result) ){
    print
"<li>";
    if(
$donor->{business} ){
      print
$donor->{business};
    }elseif(
$donor->{option_name1} ){
      print
$donor->{option_name1};
    }else{
      print
"<i>anonymous</i>";
    }
    print
"</li>";
   
$count = $count + 1;
  }
  if(
$count==0 ){
    print
"<li><i>none</i></li>";
  }
?>

Comments

10 last donations snippet - small improvement

I've modified this snippet to be fully compatible (when it comes to layout) with Drupal 5 and its default Garland theme, perhaps it fixes the layout for Drupal 5 in general, I don't know about that. I'm just getting started with Drupal.

<?php
$result
= db_query("
    SELECT business,option_name1 FROM paypal_log ORDER BY payment_date DESC LIMIT 10
  "
);
 
$count = 0;
  print
'<div class="item-list"><ul>';
  while(
$donor = db_fetch_object($result) ){
    print
'<li>';
    if(
$donor->{business} ){
      print
$donor->{business};
    }elseif(
$donor->{option_name1} ){
      print
$donor->{option_name1};
    }else{
      print
'<i>anonymous</i>';
    }
    print
'</li>';
   
$count = $count + 1;
  }
  if(
$count==0 ){
    print
'<li><i>none</i></li>';
  }
  print
'</ul></div>';
?>

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.