<?php

//fetch_data.php
define('DB_HOST', 'localhost');
define('DB_NAME', 'xml');
define('DB_USER', 'root');
define('DB_PASS', '');

$connect = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8", DB_USER, DB_PASS);

if(isset($_POST["action"]))
{
 $query = "
  SELECT * FROM item WHERE 1
 ";
 if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"]))
 {
  $query .= "
   AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."'
  ";
 }
 if(isset($_POST["brand"]))
 {
  $brand_filter = implode("','", $_POST["brand"]);
  $query .= "
   AND manufacturer IN('".$brand_filter."')
  ";
 }
 if(isset($_POST["ip"]))
 {
  $ram_filter = implode("','", $_POST["ip"]);
  $query .= "
   AND name IN('".$ram_filter."')
  ";
 }


 $statement = $connect->prepare($query);
 $statement->execute();
 $result = $statement->fetchAll();
 $total_row = $statement->rowCount();
 $output = '';
 if($total_row > 0)
 {
  foreach($result as $row)
  {
   $output .= '
   <div class="col-sm-4 col-lg-3 col-md-3">
    <div style="border:0.5px solid #ccc; border-radius:25px; padding:0px; margin-bottom:6px; height:200px;">
     <img src="'. $row['image'] .'" style="width:50px; height:50px;">
	 </br>
     <p align="center"><strong><a href="#">'. $row['name'] .'</a></strong></p>
     <p style="text-align:bottom;" class="text-danger" ><strong>'. $row['price'] .' лв.</strong> </p>
    
    </div>

   </div>
   ';
  }
 }
 else
 {
  $output = '<h3>No Data Found</h3>';
 }
 echo $output;
}

?>
