<?php
include('config.php');
$connect = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
$lang = $_GET['language'];

$res = mysqli_query($connect,"SELECT id FROM `catalog` where name = '$lang' and product_id=467");

$row = mysqli_fetch_assoc($res);

$id = $row['id'];


$res1 = mysqli_query($connect, "SELECT * FROM `catalog` where pid= $id");

//$row1 = mysqli_fetch_assoc($res1);
$movies = array();
$movie_list = array();


while($row1 = mysqli_fetch_assoc($res1)){

 $c_id = $row1['id'];
 $c_name = $row1['name'];
$lang_videos = array();
$movies['product_id'] = 367;
$movies['category_id'] = $c_id;
$movies['category_name'] = $c_name;


$res2 = mysqli_query($connect, "select cr.id, cr.name,cr.url,cr.starcast,cr.rating,cr.director,cr.description,cr.cert,cr.genre,
cr.language,cr.released,cr.ctype from cms.content cn, repo.contentdata cr where 
  cn.content_id = cr.id and cn.catalog_id=$c_id");


//$movie_list = array();

while($rows = mysqli_fetch_array($res2)){
//echo "dsf";
//$row_array['date'] = $rows['cdt'];
//$row_array['percentage'] = $rows['percentage'];
$row_array['name'] = $rows['name'];
$row_array['youtube_url'] = $rows['url'];
$row_array['starcast'] = $rows['starcast'];
$row_array['rating'] = $rows['rating'];
$row_array['director'] = $rows['director'];
//$row_array['description'] = $rows['description'];
$row_array['certificate'] = $rows['cert'];
$row_array['genre'] = $rows['genre'];
$row_array['language'] = $rows['language'];
$row_array['released'] = $rows['released'];
$row_array['content_type'] = $rows['ctype'];
$row_array['content_id']= $rows['id'];
$cid = $rows['id'];
//$row_array['thumb'] = $rows['thumb'];
$ctype =  $rows['ctype'];
 $row_array['image_url'] = "thumbnail.php?c_id=$cid&ctype=$ctype";

 $row_array['description'] = utf8_encode($rows['description']);


 array_push($movie_list,$row_array);


}
//$movie_list1 = array();
//$movies_list1= array("product_id"=>"467","category_id"=>$c_id,"category_name"=>$c_name,"videos"=>$movie_list);
//array_push($movies,$movie_list1);
$movies['videos'] = $movie_list;
//header('Content-Type: application/json');
}
$list = array();

array_push($list,$movies);
header('Content-Type: application/json');




if (empty($list)) {

                                                                                                                         
$array = array("code"=>"200","message"=>"No movies are found.!");

echo json_encode($array);

} else{
echo json_encode($list);
}


//echo json_encode($movie_list);

//mysqli_close($repo);
mysqli_close($repolink);








?>
