Since we launched the comment contest we have been somewhat bombarded with questions. Everything from how it works to if we can share the “plugin” we used for it.

First off its not a plugin its some code I hacked together. I think by answering some of these it will also explain why the code below does what it does. Its really all in the sql querry.

What post do I have to comment on to win daily?

The winner is randomly selected from comments made on that day at 23:55.

If I spam all past posts with comments does that help?

No it has to be from a comment on the days post.

If you don’t post anything today can I win by commenting on previous ones?

No its only on that day.

So again when a post is made you come in and comment you are entered to win. Hopefully that is straight forward enough.

Now the biggest question was what plugin we used to make it happen. Again its not a plugin. To make the random selection happen many things had to come into play and lots of cross table selects. I am sure this code is far from perfect as I, yes me, did it. With my lack of programing ability this took me a long time to figure out.

It was difficult for me because of all the factors in play:

  • It had to select a random commentator.
  • It had to select the commentator from a post made that day.
  • it had to select from ONLY posts that were published (I made lots of drafts).
  • It had to select from only posts and NOT pages.
  • It had to select from the proper wordpress post type (we have custom post types for stuff like marketplace and what not).
  • It had to select uniq from that day.
  • IT had to have a user with an email (so we can contact them).
  • It had to have a user that had an approved comment.
  • It had to not have me as a eligible winner.

I also want to automatically:

  • Email the winner.
  • Email the person on my staff who will ship these out.
  • BCC email myself so I know its working nightly.
  • Put a unique code in the subject line so we can properly track it and authenticate it.

So here is the code that makes all that happen:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
< ?
$today=date("Y-m-d");
 
$db_host = "localhost";
$db_user = "dbusername";
$db_passwd = "password";
$db_db = "database";
 
mysql_connect("$db_host","$db_user","$db_passwd");
mysql_select_db("$db_db");
 
$result=mysql_query("select comment_author,comment_author_email,comment_author_url,comment_content, comment_date from wp2_comments where comment_author_email NOT IN (SELECT email FROM commentcontest) AND comment_author !='shoemoney' AND comment_approved=1 AND comment_post_id =(select id from wp2_posts where post_status ='publish' AND post_type = 'post' AND  post_date like '$today%' order by post_date limit 1) order by rand() limit 1");
 
while($row = mysql_fetch_object($result))
                {
 
                $author = $row->comment_author;
                   $email = $row->comment_author_email;
                   $url = $row->comment_author_url;
                   $content = $row->comment_content;
                   $comment_date = $row->comment_date;
                }
 
if (!$email=='') {
 
$content=addslashes($content);
$code =md5($email);
 
$subject = "$today ShoeMoney Comment Contest Winner $code";
 
        $headers = "Return-Path: annasemail@shoemoney.com\r\n";
        $headers .= "From: Anna <annasemail @shoemoney.com>\r\n";
        $headers .= 'Bcc: Jeremy <jeremy @shoemoney.com>' . "\r\n";
 
$message = "Dear $author,
 
Congratulations!  You are the randomly selected winner for your comments written on a shoemoney.com blog post on $today. You have won a ShoeMoney t-Shirt and a chance at this months grand prize! \nTo Claim your t-shirt Please reply to this email with your shirt size, style of shirt (male or female Small to XXXL),  and your mailing address.\n We will ship them to you free of charge anywhere in the world!  Please respond to this email within 48 hours with your address if you wish to claim your free shirt!\nCongratulations and good luck at winning this months grand prize.  For more information check http://www.shoemoney.com/commentcontest/
 
Please note - We ship out shirts on the first and 15th of each month. \n
 
Also please keep the subject line with the code intact so we can verify its authenticity!i\n
 
Thanks for your contribution to the ShoeMoney Blog!  We appreciate your support and input!\n
 
Jeremy Schoemaker AKA ShoeMoney";
 
        mail($email,$subject,$message,$headers);
 
mysql_query("INSERT INTO commentcontest(doc,author,email,url,content) VALUES('$today','$author','$email','$url','$content')")  or die(mysql_error());
 
print "$author $email $url $content $comment_date";
} else {
 
        die("no data\n\n");
}
?>
</jeremy></annasemail>

Then for the actual page that shows the winners I select from that from the winners to show on the comment contest results page:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
< ?php
$db_host = "localhost";
$db_user = "dbusername";
$db_passwd = "password";
$db_db = "db";
 
mysql_connect("$db_host","$db_user","$db_passwd");
mysql_select_db("$db_db");
$contestdate=date('F Y');
?>
<table>
<tr>
<td>Date</td>
<td>Winner Name</td>
<td>Comment</td>
</tr>
 
< ?php
$result=mysql_query("select * from commentcontest where dtime > '2008-12-01 00:00:00' order by dtime DESC");
 
while($row = mysql_fetch_object($result))   {
 
                $doc=$row->doc;
                        $author = $row->author;
                $url = $row->url;
                $content = $row->content;
                $comment_date = $row->comment_date;
print "
<tr>
<td>$doc</td>
<td><a href=\"$url\">$author</a></td>
<td>$content</td>
</tr>
 
";
}
echo  "</table>
 
";
?>

. So again its not a plugin and with the code above if you want to do it, it should save you a lot of time whether you do it yourself or hire some monkey off of Odesk.

BTW if your going to hate on my code at least offer suggestions on how to improve it =P If someone wants to turn this into a plugin go ahead.

{ 16 comments }


Michelle recommends you check out these amazing posts:

  1. YouTube - problogger darren rowse interview at blogworld The Accidental Millionaires
  2. Delicious-20100219-073418 Using Delicious to Understand Your Users
  3. shutterstock_68611039 How To Profit From Invading Your Users Privacy

Free Shirt Friday – I Heart Booty

April 20, 2012

Ohhh hell yeah I ♥ Booty, who it their right mind doesn’t? But on a more serious note I ♥ Booty products are here to help promote the dreadful colon cancer that can often be a touchy subject. So next time you see someone rockin’ this shirt around town it will work as an excellent [...]

4 comments Read the full article →

Join us live – testing ShoeMoney.tv

April 20, 2012
Thumbnail image for Join us live – testing ShoeMoney.tv

We are getting ready to launch ShoeMoney.tv

4 comments Read the full article →

Hope and change baby

April 20, 2012
Thumbnail image for Hope and change baby

A local Lincoln Artist brought this in. It was a gift from my assistant.

7 comments Read the full article →

Killing it bidding on misspellings in Adwords? Your screwed.

April 19, 2012
Thumbnail image for Killing it bidding on misspellings in Adwords?  Your screwed.

Most experienced AdWords advertisers have developed keyword lists that include things like misspellings, plurals, and other variations on a keyword or phrase. Now, Google will do all this automatically — as it does with organic results — with exact and phrase matching, though advertisers will be able to opt out. The new behavior will take [...]

7 comments Read the full article →

My Short-Lived Obsession with Foursquare and My Growing Concern for Privacy

April 18, 2012
Thumbnail image for My Short-Lived Obsession with Foursquare and My Growing Concern for Privacy

I signed up for Foursquare, the app that lets you check into various locations and unlock badges and deals, shortly after it launched (yes, I’m pulling the “hipster” card on you) at the suggestion of a friend. It was a novel concept at the time, and I found the gaming aspects to be a great [...]

4 comments Read the full article →

How to Become the Next SEO Rock Star

April 18, 2012
Thumbnail image for How to Become the Next SEO Rock Star

Do you dream of being the next Shoemoney?  Or want to become SEO household name like Danny Sullivan?  Or get SEO rock star famous like Greg Boser and Todd Friesen?  Well, in order to do that you have to stop being an unknown and get your ass into the coveted group of SEOs who are, [...]

30 comments Read the full article →

Why we are not friends on Facebook (dont take it personal)

April 17, 2012
Thumbnail image for Why we are not friends on Facebook (dont take it personal)

So like I have been meaning to post this for a bit but I feel it kind of comes off as egotistical. Here is the deal. I get a lot of friend requests. I don’t check them. In fact I think today was the first time I friended someone in 4 months. I have a [...]

19 comments Read the full article →

Pure Country- Free Shirt Friday

April 13, 2012
Thumbnail image for Pure Country- Free Shirt Friday

If you like to model your tiny dog around in different types of costumes then Pure Country is perfect for you. Check it out for different types of costumes for all dogs 12 pounds and under. Check out our office dog Walter showing off his new duds from Pure Country.   If you would like to [...]

19 comments Read the full article →

ShoeMoney iPhone & iPad Affiliate Marketing Free for a limited time!

April 12, 2012
Thumbnail image for ShoeMoney iPhone & iPad Affiliate Marketing Free for a limited time!

I am pretty pumped!!! If you remember a few weeks back I said I went to Los Angeles to shoot a TON of brand new content. It was all for an iPhone / Ipad application. For ShoeMoney readers we are giving it out for a limited time. Click here to download it now. Here is [...]

23 comments Read the full article →

Why you have been blackballed by the SEO Inner Circle

April 11, 2012
Thumbnail image for Why you have been blackballed by the SEO Inner Circle

Ever wonder why you aren’t in the “in crowd” or why you aren’t invited to any of the many super-secret forums/groups/backrooms/dinners in the SEO industry?  Why people clam up when you join up with them at the bar at any SEO conference?  Or your @replies to top industry people seemingly go unnoticed?  While you might [...]

40 comments Read the full article →

The ShoeMoney Comment Contest is back!

April 10, 2012
Thumbnail image for The ShoeMoney Comment Contest is back!

Back by popular demand is the ShoeMoney comment contest. The comment contest works like this. Basically you drop by and give your take on the days post. When you comment you are automatically entered in the daily contest. Daily contest winners will be put into the grand prize drawing of an iPad 3! Thats it [...]

62 comments Read the full article →

It’s the Training, Not the Destination: The Endurance Sport of Online Marketing

April 9, 2012
Thumbnail image for It’s the Training, Not the Destination: The Endurance Sport of Online Marketing

I’m currently training for an Ironman. It’s not my first time tackling the distance–I completed my first Ironman in 2010, and have been involved in endurance sports since 2006. Whenever a non-triathlete or someone who isn’t familiar with the sport hears that I’m planning to race in an Ironman this August, the response is generally [...]

10 comments Read the full article →

Does the New FTC “Biz-Op” Rule Cover Internet “Make-Money” Schemes?

April 9, 2012
Thumbnail image for Does the New FTC “Biz-Op” Rule Cover Internet “Make-Money” Schemes?

Most antiquities remain forever relics of the past, irrelevant to the present except as objects of interest and amusement. Such had seemed to be the case with the FTC’s dusty old Business Opportunity (“Biz-Op”) Rule, but no more. Once confined to the realm of vending machine businesses and the like, and limited to biz-ops costing [...]

3 comments Read the full article →

Commercial Silk- Free Shirt Friday

April 6, 2012
Thumbnail image for Commercial Silk- Free Shirt Friday

As the premier makers of artificial trees Commercial Silk will give you the best, in saying that, thanks for the Red Bull and Belvedere. Nothing says great artificial tress like vodka and energy drinks. If you would like to see your website or company featured on Free Shirt Friday click here

1 comment Read the full article →