HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/nclive/backend/state_data.php
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include "config.php";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); 
$max=50;
//$min=$_REQUEST['pageN'];
$min=isset($_GET['page']) ? $_GET['page'] : 1;
$countpage = ($min - 1) * $max;

$subquery="";


$type=$_REQUEST['type'];
/* $state_id=$_REQUEST['state_id'];
$city_id=$_REQUEST['city'];  */
$state_id=isset($_REQUEST['state_id']) ? $_REQUEST['state_id'] : "";
$city_id=isset($_REQUEST['city']) ? $_REQUEST['city'] : "";
$subquery="";



/* ********* type  ***************/

if($type=="kvs" OR $type=="nvs"){	

if($state_id!=NULL AND $city_id==NULL ){
if($state_id==0){
$subquery="";	
}	else{
	$subquery="and tab.state_id='$state_id'";
}}
else if($state_id!=NULL AND $city_id!=NULL){
if($city_id==0){
$subquery="";		
}
else{	
	$subquery="and tab.city_id='$city_id' and tab.state_id='$state_id'";
}}

else{
	$subquery="";
}
$count="SELECT count(*) as total FROM sp_kvs_navodya as tab WHERE tab.type='$type' $subquery";
	
$query="SELECT tab.id, tab.type, tab.name, tab.state_id,s.state_name,s.image_icon,c.city, tab.city_id, tab.pincode, tab.address, tab.longitude, tab.latitude, tab.important_emails,tab.important_phones, tab.official_website_link, tab.online_apply_link, tab.online_fee_link, tab.result_link, tab.addmission_guidelines, tab.addmission_details, tab.other_info, tab.display_order, tab.status FROM sp_kvs_navodya as tab
left join sp_states as s on s.state_id=tab.state_id
left join sp_city as c on c.city_id=tab.city_id
 WHERE tab.type='$type' $subquery ORDER BY s.state_name,c.city ASC limit $countpage,$max";



$amt=$db->prepare($count);
$amt->execute();
$cnt=$amt->fetch();
$countresult=$cnt['total'];
$div= ceil($countresult / $max);


$sql=$db->prepare($query);
$sql->execute();
$mainarray=array();
while($row=$sql->fetch()){	
$name=$row['name'];
$state_id=$row['state_id'];
$statename=$row['state_name'];
$stateimage=$row['image_icon'];
$city_id=$row['city_id'];
$cityname=$row['city'];
$pin=$row['pincode'];
$add=$row['address'];
$lon=$row['longitude'];
$lat=$row['latitude'];
$imp_email=$row['important_emails'];
$imp_phone=$row['important_phones'];
$web=$row['official_website_link'];
$guide=$row['addmission_guidelines'];
$details=$row['addmission_details'];
$on_applylink=$row['online_apply_link'];
$on_feelink=$row['online_fee_link'];	
$res_link=$row['result_link'];
$array=array("name"=>$name,"state_id"=>$state_id,"statename"=>$statename,"stateimage"=>$stateimage,"city_id"=>$city_id,"cityname"=>$cityname,"pincode"=>$pin,"address"=>$add,"longitude"=>$lon,"latitude"=>$lat,"important_email"=>$imp_email,"important_phone"=>$imp_phone,"website_link"=>$web,"addmission_guidelines"=>$guide,"addmission_details"=>$details,"apply_link"=>$on_applylink,"fee_link"=>$on_feelink,"result_link"=>$res_link);

$mainarray[]=$array;	
}
$array2=array("Total"=>$countresult,"no_of_page"=>$div,"cur_page"=>$min,"data"=>$mainarray);
if($array2["data"]!=null){
$mainsub8[]=$array2;	
echo json_encode($mainsub8 , TRUE);
}else
echo "No data found";
}



if($type=="exam"){
$count2="SELECT count(*) as total FROM sp_exam as t1 WHERE t1.state_id='$state_id'";
	
$query2="SELECT t1.exam_id, t1.exam_name, t1.post_name, t1.exam_summary, t1.url_slug, t1.qualification_id, t1.qualification_desc, t1.age_id, t1.age_desc, t1.fee_desc, t1.physical, t1.total_vacancy, t1.total_question, t1.total_marks, t1.exam_mode, t1.negative_marking, t1.off_web_link, t1.display_order FROM sp_exam as t1 WHERE t1.state_id='$state_id' ORDER BY t1.add_date DESC limit $countpage,$max";

$amt2=$db->prepare($count2);
$amt2->execute();
$cnt2=$amt2->fetch();
$countresult2=$cnt2['total'];
$div2= ceil($countresult2 / $max);


$sql2=$db->prepare($query2);
$sql2->execute();
while($row2=$sql2->fetch()){	
$exam_id= $row2['exam_id'];
$exam_name= $row2['exam_name'];
$url_slug= $row2['url_slug'];


$query3="SELECT `exam_id`, `entity_id`, `display_text`, `description`, `links`, `date_type`, `date` FROM `sp_exam_links` WHERE exam_id='$exam_id'  ORDER by update_date DESC";
$sql3=$db->prepare($query3);
$sql3->execute();
$mainsub2 = array();
while($row3=$sql3->fetch()){
$links=$row3["links"];
$display_text=$row3["display_text"];
$date_type=$row3["date_type"];
$dates=$row3["date"];
$date="";
if($date_type=="N"){
$d=explode(",",$dates);
$e=array();
for($p=0;$p<count($d);$p++){
$new_date = date('d-m-Y', strtotime($d[$p]));
$e[]=$new_date;
$date=implode(" ,",$e);
}}
if($date_type=="FT"){
$dd=explode(",",$dates);
$date1 = date('d-m-Y', strtotime($dd[0]));
$date2 = date('d-m-Y', strtotime($dd[1]));
$date=' From '.$date1.' To '.$date2;
}

$array3=array("name"=>$exam_name,"links"=>$links,"url_slug"=>$url_slug,"display_text"=>$display_text,"date"=>$date,"date_type"=>$date_type);
$mainsub2[]=$array3;
}

$array4=array("exam_id"=>$exam_id,"exam_name"=>$exam_name,"url_slug"=>$url_slug,"link"=>$mainsub2);
$mainsub[]=$array4;
}	
$array8=array("Total"=>$countresult2,"no_of_page"=>$div2,"cur_page"=>$min,"data"=>$mainsub);
$mainsub8[]=$array8;
echo json_encode($mainsub8 , TRUE);
}





?>