<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once('../lib/dbclass.php');



$challenge_startdate = date('Y-m-d');


$data = findQuery("select * from  `tbl_challenge` where '$challenge_startdate'  between `challenge_startdate` and `challenge_enddate` and status=0");











if ($data) {
    for ($i = 0;$i < count($data);$i++) {
        $message = 'true';

        $product_name2   = '';
        $product_image2  = '';
        $product_amount2 = '';
        $delivary_date2  = '';

        $sponsorproductid1 = $data[$i]['sponsorproductid1'];
        $sponsorproductid2 = $data[$i]['sponsorproductid2'];
        $sponsorproductid3 = $data[$i]['sponsorproductid3'];
        $sponsorproductid4 = $data[$i]['sponsorproductid4'];
        $sponsorproductid5 = $data[$i]['sponsorproductid5'];

        $prod1 = '';
        $prod2 = '';
        $prod3 = '';
        $prod4 = '';
        $prod5 = '';

        $rate1 = 0;
        $rate2 = 0;
        $rate3 = 0;
        $rate4 = 0;
        $rate5 = 0;

        if ($sponsorproductid1 > 0) {
            $datasponsor = findQuery("select * from  `tbl_product` where id=$sponsorproductid1");
            $prod1       = $datasponsor[0]['product_name'];
            $rate1       = $data[$i]['rate1'];
        }

        if ($sponsorproductid2 > 0) {
            $datasponsor = findQuery("select * from  `tbl_product` where id=$sponsorproductid2");
            $prod2       = $datasponsor[0]['product_name'];
            $rate2       = $data[$i]['rate2'];
        }

        if ($sponsorproductid3 > 0) {
            $datasponsor = findQuery("select * from  `tbl_product` where id=$sponsorproductid3");
            $prod3       = $datasponsor[0]['product_name'];
            $rate3       = $data[$i]['rate3'];
        }

        if ($sponsorproductid4 > 0) {
            $datasponsor = findQuery("select * from  `tbl_product` where id=$sponsorproductid4");
            $prod4       = $datasponsor[0]['product_name'];
            $rate4       = $data[$i]['rate4'];
        }

        if ($sponsorproductid5 > 0) {
            $datasponsor = findQuery("select * from  `tbl_product` where id=$sponsorproductid5");
            $prod5       = $datasponsor[0]['product_name'];
            $rate5       = $data[$i]['rate5'];
        }



        $data2[] = [


'id1'   => $sponsorproductid1,
'1'     => $prod1,
'rate1' => $rate1,
'id2'   => $sponsorproductid2,
'2'     => $prod2,
'rate2' => $rate2,
'id3'   => $sponsorproductid3,
'3'     => $prod3,
'rate3' => $rate3,
'id4'   => $sponsorproductid4,
'4'     => $prod4,
'rate4' => $rate4,
'id5'   => $sponsorproductid5,
'5'     => $prod5,
'rate5' => $rate5,










            ];
    }
} else {
    $message = 'false';
    $data2[] = ['error' => 'Not Found'];
}

echo json_encode(['Status' => $message, 'data' => $data2]);

return;

?>

