<?php
//To get category and sub categories for dynamic questions

require_once __DIR__ . '/db_config.php';

$r = array();

$r["cats"] = array();
$r["subcats"] = array();

if (isset($_POST["cname"]) ) {
 
$cname=$_POST["cname"];
$email=$_POST["mail"];
date_default_timezone_set('Asia/Calcutta');
$date=date('Y-m-d');

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$query="SELECT id,category FROM dynamicquestionscategory WHERE companyname='$cname' AND deleted='no'";

$result=mysqli_query($con,$query);

if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["cats"], $row);
    }
}

$query="SELECT id,category,subcategory FROM dynamicquestionssubcategory WHERE companyname='$cname' AND deleted='no'";
$result=mysqli_query($con,$query);

if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["subcats"], $row);
    }
}

}

echo json_encode($r);

?>