<?php
header('Content-type: application/json');
include '../config/database.php';
function _results($Product){
	$conn = _connectDB();
	$sql = "SELECT * FROM result WHERE rcategory = '".$Product."' ORDER BY rid + 0 ASC LIMIT 300;";

	$result = $conn->query($sql);
	$res = [];
	if ($result->num_rows > 0) {
	    while($row = $result->fetch_assoc()) {
			array_push($res,$row);
	    }
	}
	return $res;
}
if(isset($_GET['p'])){
	$Product = $_GET['p'];
	$newOBJ = [];
	foreach (_results($Product) as $key => $value) {
		array_push($newOBJ,  $value);
	}
	echo json_encode($newOBJ);
}else{
	echo json_encode([]);
}




// SELECT * FROM `05z3l_linebot_demo`.`result` ORDER BY `rtime` DESC, `rgendate` ASC, `rname` ASC, `rid` ASC, `r3unit` ASC, `r2unit` ASC, `r3unit_vip` ASC, `r2unit_vip` ASC LIMIT 1000;