<?php 
/**  * Creates fault detail data as JSON  */    
include_once 'db_functions.php';     
$db = new DB_Functions();     
$res_offer = $db->getOffers();     
$a = array();     
$b = array();    
if ($res_offer != false){         
while ($row_offer = mysql_fetch_array($res_offer)){
	/////// pick product detail
	$res_prd = $db->productDetail($row_offer["productcode"]);
	$row_prd = mysql_fetch_array($res_prd);
	//// get brand name
	$res_brd = $db->brandName($row_prd["brand"]);
	$row_brd = mysql_fetch_array($res_brd);
	////category name
	$res_cat = $db->catName($row_prd["productsubcat"]);
	$row_cat = mysql_fetch_array($res_cat);
	
	$b["schCode"] = $row_offer["scheme_code"];
	$b["schName"] = $row_offer["scheme_name"];
	$b["schDuration"] = "FROM ".$row_offer["from_date"]." TO ".$row_offer["to_date"];
	$b["schProduct"] = $row_prd["productname"]." | ".$row_brd["make"]." | ".$row_cat["prod_sub_cat"]." | ".$row_cat["product_category"];
	$b["schBasedType"] = $row_offer["scheme_based_type"];
	$b["schBasedOn"] = $row_offer["scheme_based_on"];
	$b["schGivenType"] = $row_offer["scheme_given_type"];
	$b["schGivenOn"] = $row_offer["scheme_given"];
		   
	array_push($a,$b);         
}         
echo json_encode($a);     
} 
?>