<?php require('includes/cmain.inc.php');?>
<?php 
$search_result = isset($_GET['search']) ? $_GET['search'] : '';
$segments = explode("=", $_SERVER["REQUEST_URI"]);
$search_query = $segments[1] ?? ''; // Assuming $segments[1] contains the search query
//print_r($search_query);exit();
$a=str_replace('%20','+',$search_query);
$search_query=$a;
//print_r($a);exit();
// Split the search query into separate words
$search_terms = explode("+", $search_query);

// Construct the SQL query dynamically
$sql_parts = array();
foreach ($search_terms as $term) {
    $sql_parts[] = "country_name LIKE '%$term%'";
}
$sql_condition = implode(" OR ", $sql_parts);
//print_r($sql_condition);exit();

$sql = "SELECT * FROM tbl_country WHERE parent_childs!=0 AND $sql_condition";
$sqlquery = db_query($sql);
$num_rows = mysqli_num_rows($sqlquery);
?>
<!DOCTYPE html>
<html lang="en">
 <style>
.container.ngh {
    margin-top:20px;
  /*  border: 3px solid #f3770c;*/
    padding: 20px 0px;
    
  /*  background: beige;*/
}

section.knowsec {
    padding: 10px;
}
.s-res{
    display:flex;
    width:100%;
    height:auto;
    margin-top:20px;
    gap:15px;
    justify-content:space-evenly;
    align-items: center;
    flex-wrap:wrap;
    
}
.search-result{
    display:flex;
   
    flex-direction:column;
    flex-wrap:wrap;
    width:25%;
    height:auto;
    margin-top:20px;
    justify-content:space-evenly;
    border: 1px solid #4ea948;;
    border-radius: 3px;
     box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px, rgba(10, 37, 64, 0.35) 0px -2px 6px 0px inset;
    
}
.search-img{
    display:flex;
     width:100%;
    height:auto;
    justify-content:center;
    align-items:center;
    padding:10px;
}
.img-search{
     display:flex;
     width:300px;
     height:300px;
}
.search-content{
    display:flex;
     width:100%;
    height:auto;
    justify-content:center;
    align-items:center;
     padding:10px;
     color:#11418a !important;
   
}
.font-class{
color:#123161;
font-weight:bold;
}
.font-class:hover{
color:#3e9538;
}
.pad-head{
    padding-top:10px;
    padding-bottom:10px;
}

@media(max-width:570px){
   .container.ngh {
    margin-top:20px;
  /*  border: 3px solid #f3770c;*/
    padding: 0px 0px;
    
  /*  background: beige;*/
}

section.knowsec {
    padding: 0px;
}
.s-res{
    display:flex;
    width:100%;
    height:auto;
    
    
}
.search-result{
    display:flex;
   
    flex-direction:column;
    flex-wrap:wrap;
    width:100%;
    height:auto;
    
}
.search-img{
    display:flex;
     width:100%;
    height:auto;
    justify-content:center;
    align-items:center;
    padding:0px;
}
.img-search{
     display:flex;
   
}
.search-content{
    display:flex;
     width:100%;
    height:auto;
    justify-content:center;
    align-items:center;
     padding:0px;
     color:#11418a !important;
   
}
}


 </style>
 <?php include('header.php'); ?>
 <section class="knowsec">
     <div class="container ngh">
        <div class="row">
           
                <h3><b>Search Results: '<?php echo ucwords($search_result);  ?>'</b> </h3>
               
              <div class="s-res">
                  
                     <?php
                   
                     while($result1=mysqli_fetch_array($sqlquery)){?>
                       <div class="search-result">
                    
            <div class="search-content">
 <h4 class="pad-head"><a href="<?php echo SITE_WS_PATH . '/' . str_replace(" ","-",(strtolower($result1['country_url']))); ?>" class="font-class"><?php echo ucwords($result1['country_name']); ?></a> <!--<img src="images/right-arrow.png" width="30" height="30"/>--></h4>

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