Skip to content

Instantly share code, notes, and snippets.

@dubrod
Created August 30, 2011 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/1180995 to your computer and use it in GitHub Desktop.
Save dubrod/1180995 to your computer and use it in GitHub Desktop.
Translate # of Twitter Followers to Discount Coupon % on osCommerce
<?php
$tweet_data = json_decode(file_get_contents("http://api.twitter.com/1/users/show.json?screen_name=YOURTWITTERNAME"), true);
// display tweet data array ( just to show you i know what i'm doing =] )
//print "<pre>";
//print_r($tweet_data);
//print "</pre>";
?>
<?php
// format likes percent
if($tweet_data["followers_count"] > 1) {
$tweet_data["followers_count"] = $tweet_data["followers_count"] * floatval("." . str_repeat(0, strlen($tweet_data["followers_count"])) . 1 );
}
print $fb_data["likes"];
// connect to DB
$db = mysql_connect("localhost","DBADMIN","DBPASSWORD") or die("DB connection failed " . mysql_error());
mysql_select_db("DATABASENAME", $db) or die("DB connection: DB select failed " . mysql_error());
// set query (protected DB with secure mysql func)
$query = sprintf("UPDATE discount_coupons SET coupons_discount_amount = '%s' WHERE coupons_id = 'COUPONCODE';",
mysql_real_escape_string($tweet_data["followers_count"]));
// execute query
$success = mysql_query($query) or die("DB connection: query failed " . mysql_error());
// check for successful update
if($success) {
print "1 record updated";
} else {
print "DB connection: update failed";
}
// finally, close connection
mysql_close($db);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment