Display a Recent Donor List

Display a Recent Donor List

figs/moderate.gif figs/hack80.gif

Extend your donation system by allowing users to be recognized for their contributions.

[Hack #79] shows how to display donation goals for your web site with the intention of encouraging more and larger contributions. This hack shows how to recognize your donors for their contributions by displaying a list of the five most recent donors, the amount they donated, and a small note if the donor chooses.

1 The Donation Button

The donation button needs to be modified to present donors with two fields. The first asks whether the donor would like to have her name displayed on the web page. The second allows her to enter a short note if she wishes. As with a Buy Now button, the optional button variables on0, os0, on1, and os1 are used to pass the donor's answers along to PayPal.

As explained in PayPal's Integration Guide (https://www.paypal.com/en_US/pdf/integration_guide.pdf), the optional fields on0, os0, on1, and os1 work for donations in the same way they do for the Buy Now button. (You also won't see these options in the donation button generator under PayPal's Merchant Tools tab.)

This donation button collects the information we need. (Note the similarity to the button code in [Hack #79] .)

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="business" value="[email protected]">

<input type="hidden" name="item_name" value="Donation">

<input type="hidden" name="item_number" value="Donation-001">

<input type="hidden" name="no_note" value="1">

<input type="hidden" name="currency_code" value="USD">

<input type="hidden" name="tax" value="0">

<input type="hidden" name="on0" value="Display name on donors page">

Do you want your name displayed on the "recent donors" page?

<select name="os0">

 <option value="Yes" selected>Yes</option>

 <option value="No">No</option>



<input type="hidden" name="on1" value="Public note for donors' page">

Note for "recent donors" page (optional):

<input type="text" name="os1" maxlength="255">

<input type="image" src=


                border="0" name="submit">


When this form is submitted to PayPal by your donor, it passes the values for the optional fields along to PayPal, where the choices are displayed on the Confirm Your Payment page. This gives your donors a chance to reread the choices and use the Cancel button if they made a mistake.

2 The Database Table

The database schema for this hack is based on [Hack #82] and [Hack #83] . Those hacks cover recording the payment information and the payment detail information.

To store the donors' recognition choices, you need to add two fields to your database. You could create a new table for this information, but for simplicity, this example assumes you have added two fields—named ShowName and DonorNote, of types integer and text, respectively—to the tblPayments table, as shown in Figure.

A database table to track the donations you receive






Give 'til it hurts



Why not?



This is our entire annual budget

To make the Confirm Your Payment page look friendly and readable to your donors, set os0 to either Yes or No. When reading option_selection1 (the value sent by the donor's browser as os0), remember to look for a Yes or a No and populate your database table with a value of 1 or 0, respectively. (By the way, why does PayPal accept a variable called os0 and send you back its value in a variable called option_selection1? Why indeed....)

3 The IPN Page

Your IPN page functions much like the IPN page described in [Hack #82] . However, you need to insert two new field values, one that indicates the donor's choice whether to display her name and one to hold the donor's note:

'Create new variables and populate them

Dim ShowName

Dim DonorNote

If Request.Form("os0") = "Yes" Then

 ShowName = 1


 ShowName = 0


DonorNote = Request.Form("os1")

Include these values in the SQL statement to insert the values into the database.

INSERT INTO tblPayments (payer_email, payer_id, payment_status, txn_id, 

                mc_gross, mc_fee, payment_date, first_name, last_name) VALUES ('"

                & payer_email & "', "' & payer_id & "', '" & payment_status & "', '" 

                & txn_id & "', " & mc_gross & ", " & mc_fee & ", '" & payment_date 

                & "', '" & first_name & "', '" & last_name & "', " & ShowName 

                & ", '" & DonorNote & "')

4 The Donation Page

Now that you have the donation data flowing into your database, you can use it on your Donations page. Query the database table for the five most recent entries:

SELECT TOP 5 first_name, last_name, mc_gross, ShowName, DonorNote 

                FROM tblPaymnets ORDER BY Id DESC

See the "Database Coding and Platform Choices" section of the Preface for the additional information needed to put this SQL statement to work with this and the other hacks in this book.

Once the query has been made, iterate over the five records and display each one, substituting Anonymous for any donors who choose not to be acknowledged publicly:


While NOT rsDonation.EOF




<% If rsDonation("ShowName") = 1 Then 'Show the name %>

<%=rsDonation("first_name")%> <%=rsDOnation("last_name")%>

<% Else 'Do not show the name %>


<% End If %>

Amount: <%=rsDonation("mc_gross")%>

<% If rsDonation("DonorNote") <> "" Then 'Note is not empty, show note %>

Note: <% rsDonation("DonorNoate")%>

<% End If %>



 rsDonation.MoveNext( )



5 Hacking the Hack

You can encourage more donations—and donations of higher values—by displaying lists of the most generous and the most recent donors.

Query the database for the top five donations by amount, sorted with the largest donation first:

SELECT TOP 5 first_name, last_name, mc_gross, ShowName, DonorNote 

                FROM tblPaymnets ORDER BY mc_gross DESC

The code to display this information is identical to the code used in the previous section of this hack.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows