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/instituteapi.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=10;
//$min=$_REQUEST['pageN'];
$min=isset($_GET['page']) ? $_GET['page'] : 1;
$count = ($min - 1) * $max;

$state_id=isset($_GET['state_id']) ? $_GET['state_id'] : "";
$city=isset($_GET['city']) ? $_GET['city'] : "";
$institute_id=isset($_GET['institute']) ? $_GET['institute'] : "";


if($state_id!=null and $city==null and $institute_id==null){
$subquery="where t1.state_id='$state_id'";
}
else if($state_id==null and $city!=null and $institute_id==null){
$subquery="where t1.city_id='$city'";
}
else if($state_id==null and $city==null and $institute_id!=null){
$subquery="where t2.id='$institute_id'";
}


else if($state_id!=null and $city!=null  and $institute_id==null){
$subquery="where t1.city_id='$city' and t1.state_id='$state_id'";
}

else if($state_id==null and $city!=null  and $institute_id!=null){
$subquery="where t1.city_id='$city' and t2.id='$institute_id'";
}

else if($state_id!=null and $city==null  and $institute_id!=null){
$subquery="where t1.state_id='$state_id' and t2.id='$institute_id'";
}

else{
$subquery="";
}
$coun="SELECT count(*) as total 
FROM sp_institutions AS t1
LEFT JOIN sp_institutions_category 
AS t2 ON t2.id=t1.category_id
LEFT JOIN sp_city AS t4 ON t4.city_id=t1.city_id
LEFT JOIN sp_states 
AS t3 on t3.state_id = t1.state_id $subquery ";
$amt=$db->prepare($coun);
$amt->execute();
$cnt=$amt->fetch();
$countresult=$cnt['total'];
$div= ceil($countresult / $max);


$query="SELECT t1.id,t1.category_id,t1.city_id,t1.institutions_name,t1.address,t4.city,t1.pincode,t1.longitude
,t1.latitude,t1.important_emails,t1.important_phones
,t1.official_website_link,t1.online_apply_link
,t1.online_fee_link,t1.result_link,t1.other_info
,t1.display_order,t1.status,t1.added_date
,t2.category_name,t3.state_name 
FROM sp_institutions AS t1
LEFT JOIN sp_institutions_category 
AS t2 ON t2.id=t1.category_id
LEFT JOIN sp_city AS t4 ON t4.city_id=t1.city_id
LEFT JOIN sp_states 
AS t3 on t3.state_id = t1.state_id $subquery limit $count,$max";

$sql2=$db->prepare($query);
$sql2->execute();

$mainSub = array();
$mainSub2 = array();

while($row=$sql2->fetch()){	
$cityname=$row['city'];
$cid=$row['category_id'];
$city=$row['city_id'];
$name=$row['category_name'];
$institutions_name=$row['institutions_name'];
$address=$row['address'];
$state_name=$row['state_name'];
$pincode=$row['pincode'];
$important_emails=$row['important_emails'];
$important_phones=$row['important_phones'];
$official_website_link=$row['official_website_link'];
$online_apply_link=$row['online_apply_link'];
$online_fee_link=$row['online_fee_link'];
$result_link=$row['result_link'];
$other_info=$row['other_info'];
$latitude=$row['latitude'];
$longitude=$row['longitude'];
$display_order=$row['display_order'];
$status=$row['status'];
$added_date=$row['added_date'];

$main=array("Category_Id"=>$cid,"Category_Name"=>$name,"Institutions_Name"=>$institutions_name,"address"=>$address,"State_Name"=>$state_name,"City"=>$city,"City_Name"=>$cityname,"Pincode"=>$pincode,"Important_Emails"=>$important_emails,"Important_Phones"=>$important_phones,"Official_Website_Link"=>$official_website_link,"Online_Apply_Link"=>$online_apply_link,"Online_Fee_Link"=>$online_fee_link,"Result_Link"=>$result_link,"Other_Info"=>$other_info,"Latitude"=>$latitude,"Longitude"=>$longitude,"Display_Order"=>$display_order,"Status"=>$status,"Added_Date"=>$added_date);
$mainSub[]=$main;
}

$array=array("Total"=>$countresult,"no_of_page"=>$div,"cur_page"=>$min,"data"=>$mainSub);	
$mainsub2[]=$array;	
//$mainarray=array("data"=>$a);
//print_r($mainarray);

echo json_encode($mainsub2);

?>