Skip to content

Instantly share code, notes, and snippets.

@underdown
Created October 24, 2013 21:18
Show Gist options
  • Select an option

  • Save underdown/7145169 to your computer and use it in GitHub Desktop.

Select an option

Save underdown/7145169 to your computer and use it in GitHub Desktop.
Push X-Cart sales stats to json format for geckoboard (polling - (number and secondary number)- needs some authentication)
<?php
$username = "username";
$password = "pass";
$hostname = "localhost";
$db = "dbname";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db($db, $dbhandle)
or die("Could not select db");
$result = mysql_query("SELECT SUM(total) FROM `xcart_orders` WHERE `date` BETWEEN UNIX_TIMESTAMP(SUBDATE(current_date, INTERVAL 30 DAY)) AND UNIX_TIMESTAMP(SUBDATE(current_date, INTERVAL 1 DAY)) AND `status` LIKE 'P' OR 'C'");
$row = mysql_fetch_row($result);
$result2 = mysql_query("SELECT SUM(total) FROM `xcart_orders` WHERE `date` BETWEEN UNIX_TIMESTAMP(SUBDATE(current_date, INTERVAL 60 DAY)) AND UNIX_TIMESTAMP(SUBDATE(current_date, INTERVAL 31 DAY)) AND `status` LIKE 'P' OR 'C'");
$row2 = mysql_fetch_row($result2);
if($row)
if(!isset($row[0])) $row[0] = "0";
if(!isset($row2[0])) $row2[0] = "0";
echo "{\"item\":[{\"text\":\"This Month\",\"value\":\"".$row[0]."\"},{\"text\":\"Last Month\",\"value\":\"".$row2[0]."\"}]}";
?>
@underdown

Copy link
Copy Markdown
Author

technically this is 30 days and not a month

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment