<?
$mysqli = new mysqli('78.108.80.99', 'u155520', 'x8KXQDhM8A3VVGmqXTbNKSAKZtnGhBPQ', 'b155520_coppandgross');

$resp = array();

if($result = $mysqli->query("SELECT op.product_id, op.model, opd.name, op.price, cd.name as category, cd.category_id as categoryID 
				FROM oc_product op
				JOIN oc_product_description opd ON opd.product_id = op.product_id
		                JOIN oc_product_to_category ptc ON ptc.product_id=op.product_id
                		JOIN oc_category oc ON oc.category_id = ptc.category_id
		                JOIN oc_category_description cd ON cd.category_id = oc.category_id
				", MYSQLI_USE_RESULT)
  ) {
	$index = 0;
	while($obj = $result->fetch_object()) { 

		$resp[$index]['id'] = $obj->product_id;
		$resp[$index]['model'] = $obj->model;
		$resp[$index]['name'] = iconv("cp1251","utf-8", $obj->name);
		$resp[$index]['categoryName'] = iconv("cp1251","utf-8", $obj->category);
		$resp[$index]['categoryID'] = $obj->categoryID;
		$resp[$index]['price'] = $obj->price;

		$index++;
        } 
}

$ret = array("success"=>true, "data" => $resp);

echo json_encode($ret);














