<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'Restax_final');

define('DB_PASSWORD', 'Restax_final123');

define('DB_NAME', 'Restax_api_data'); 

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

$id = $request->getAttribute('id');

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$topic_name = array();
$response=array();
$g = 0;

//doubt

    // $id=$_POST['id'];
    $sql = "SELECT  * FROM  set_syllabus where paper= $id";

    $result = $con->query($sql);

  

    while($row = $result->fetch_assoc())
    {
      $users=$row;
    //  $users_sec = $users['paper_name'];
 $users = json_decode($row['paper_name']);
    }

    $userindex = $users[0];
    $units_a = $userindex->units;
    $chapters = $units_a[0]->chapters;
    $topics = $chapters[0]->topics;

$topics_count = count($topics);

for($ij = 0; $ij<$topics_count;$ij++)
{
    if($topics[$ij]->checked == true)
    {
        $topic_name_data['topic_name']= $topics[$ij]->topicName;
        array_push($topic_name,$topic_name_data);
    }
    else{
       
    }
}

//print_r($topic_name);
//print_r($topics);
echo json_encode($topic_name);
    
?>

