File: /home/barbeatleanalyti/public_html/api.beatleanalytics.com/customer/get_points.php
<?php
/*
* Following code will get single department details
* A industry is identified by dept_id
*/
// array for JSON response
$response = array();
// include db connect class
require_once 'db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["user_id"])) {
$user_id = $_GET['user_id'];
// get a deptId from beatle_industry table
$result = mysql_query("SELECT sum(Amount) as totalPoint FROM beatle_points WHERE UserID LIKE '$user_id' ")or die(mysql_error());
$result2 = mysql_query("SELECT sum(Amount) as totalPoint FROM beatle_points WHERE UserID LIKE '$user_id' AND IsRedeem LIKE 'Y' ")or die(mysql_error());
$result3 = mysql_query("SELECT sum(Amount) as totalPoint FROM beatle_points WHERE UserID LIKE '$user_id' AND IsRedeem LIKE 'N' ")or die(mysql_error());
if (!empty($result) and !empty($result2) and !empty($result3)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
$pointDetail = array();
$pointDetail["total_points"] = $row["totalPoint"];
$pointDetail["redeem_points"] = mysql_fetch_assoc($result2)["totalPoint"];
$pointDetail["left_points"] = mysql_fetch_assoc($result3)["totalPoint"];
// success
$response["success"] = 1;
// user node
$response["pointDetail"] = array();
array_push($response["pointDetail"], $pointDetail);
// echoing JSON response
echo json_encode($response);
} else {
// no industry found
$response["success"] = 0;
$response["message"] = "No points found.";
// echo no users JSON
echo json_encode($response);
}
} else {
// no industry found
$response["success"] = 0;
$response["message"] = "No points found.";
// echo no users JSON
echo json_encode($response);
}
}else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>