<?php require('includes/cmain.inc.php');?> 
<?php
$qs1=explode("/",$_SERVER["REQUEST_URI"]);
$countryName=str_replace('-',' ',$qs1[1]);
$banner_match = ucwords(stripslashes($countryName));
$stateName=str_replace('-',' ',$qs1[2]);	
$SpCountyName =trim($qs1[3]);
$countyName = str_replace('-',' ',$SpCountyName);
$location_replace = ucwords(stripslashes($countyName));
$a=SITE_WS_PATH .'/'.$qs1[1].'/'.$qs1[2].'/'.$qs1[3];
//print_r($a);exit();
 if($stateName=='tags')
{
$search_terms = explode(" ", $location_replace);
$sql_parts = array();
foreach ($search_terms as $term) {
    $sql_parts[] = "heading LIKE '%$term%'";
}
$sql_condition = implode(" OR ", $sql_parts);
$resultTag = db_query("SELECT * FROM tbl_blog WHERE $sql_condition");
while($rowTag =mysqli_fetch_array($resultTag)){
$headingTag =str_replace(" ", "-",strtolower($rowTag['heading']));

	   if(!empty($headingTag)){
		include('blog_tags.php');
		exit;
       }
       
    }
    
}

$sql_st = db_query("select county_id,county_name, county_short_name from tbl_county where `county_name` LIKE '".$countyName."' and county_status='1' and `state_id`=(select `state_id` from tbl_state where `state_name` LIKE '".$stateName."' and state_status=1) ");
$st_data = mysqli_fetch_assoc($sql_st);

$county_id=$st_data['county_id'] ?? '';
//print_r($county_id);exit();

$sqls1=db_query("select * from tbl_statecounty where county ='$county_id' and child_name LIKE '%$countryName%' and country_status='1'");
$ress1=mysqli_fetch_array($sqls1); 
//print_r($ress1);exit();

$sqls=db_query("select * from tbl_country where `country_url` LIKE '".$countryName."' and country_status=1 ");
$ress=mysqli_fetch_array($sqls); 

if((mysqli_num_rows($sql_st) !=NULL) &&  (mysqli_num_rows($sqls1) !=NULL)) {
    $meta_title = str_replace("LOCATION_REPLACE", $location_replace.', '.$st_data['county_short_name'], $ress1['title']);
	$meta_description =str_replace("LOCATION_REPLACE",$location_replace.', '.$st_data['county_short_name'],$ress1['description']);
	$meta_keyword = str_replace("LOCATION_REPLACE",$location_replace.', '.$st_data['county_short_name'],$ress1['keyword']);   
    $meta_url=$a;
}

elseif((mysqli_num_rows($sql_st) !=NULL) &&  (mysqli_num_rows($sqls) !=NULL)) {
    $meta_title = str_replace("LOCATION_REPLACE", $location_replace.', '.$st_data['county_short_name'], $ress['title']);
	$meta_description =str_replace("LOCATION_REPLACE",$location_replace.', '.$st_data['county_short_name'],$ress['description']);
	$meta_keyword = str_replace("LOCATION_REPLACE",$location_replace.', '.$st_data['county_short_name'],$ress['keyword']);  
    $meta_url=$a;
    //print_r($meta_url);exit();
} else {
	//include('tSt.php');exit;
	include('404page.php');exit;
}
?>
<?php
include('header.php');

include('index_banner.php'); ?>
<!-- Service section -->
<? //include('index_img_links.php'); ?>
<!-- Welcome sec -->
<div class="welcome-sec">
<div class="container cf">

<div class="welcome-img">
<?//include('right_menu_county.php'); ?>
</div>

<!--<h1></h1> --> <? /*if($ress['country_title'])
{ 
echo str_replace("LOCATION_REPLACE", $location_replace, stripslashes($ress['country_title'])); 
}
else
{ 
echo ucwords(stripslashes($countryName.' in '.$countyName));  
}	*/				 
?>
<ul class="breadcrumb">
<li><a href="<?php echo SITE_WS_PATH; ?>">Home</a></li>
<li><a href="<?php echo SITE_WS_PATH.'/'.$segments[1]; ?>"><?php echo ucwords(str_replace('-',' ',$segments[1])); ?></a></li>
<li><a href="<?php echo SITE_WS_PATH.'/'.$segments[1].'/'.$segments[2]; ?>"><?php echo ucwords(str_replace('-',' ',$segments[2])); ?></a></li>
<li><?php echo ucwords(str_replace('-',' ',$segments[3])); ?></li>
</ul>
<p>
<?php  
if((mysqli_num_rows($sql_st) !=NULL) &&  (mysqli_num_rows($sqls1) !=NULL)) {
$location_replace = '<b>'.ucwords(stripslashes($countyName)).'</b> ';
$desc = stripslashes($ress1['country_descriptions']);
echo str_replace("LOCATION_REPLACE", $location_replace, $desc);
}else{
$res_desc = mysqli_fetch_assoc(db_query("select country_descriptions from tbl_country where `country_name` LIKE '".$countryName."' and country_status='1'"));
$location_replace = '<b>'.ucwords(stripslashes($countyName)).'</b> ';
//LOCATION_REPLACE							 
$desc = stripslashes($res_desc['country_descriptions'] ?? '');
echo str_replace("LOCATION_REPLACE", $location_replace,$desc);
?>
</p>

<?php  $location_replace = '<b>'.ucwords(stripslashes($countyName)).'</b> ';
$desc = stripslashes($ress['country_descriptions']);
echo str_replace("LOCATION_REPLACE", $location_replace, $desc);
}
?> 



</div>
</div>
</main>
</div>
</div>
<?php include('footer.php'); ?>
