<?php


//include_once ('database_connection.php');
/*Define constant to connect to database */
DEFINE('DATABASE_USER', 'getidbiz_getidw');
DEFINE('DATABASE_PASSWORD', 'g3t!d');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'getidbiz_wines2u');


// Make the connection:
$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD,
    DATABASE_NAME);

if (!$dbc) {
    trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}

if((isset($_GET['term'])) && (isset($_GET['lang']))){
$ld = 	trim($_GET['lang']) ;
$keyword = utf8_encode($_GET['term']);
    $keyword = 	trim($keyword) ;
//$keyword = mysqli_real_escape_string($dbc, $keyword);


//$ld=$this->session->userdata('lang_id');
$query = "SELECT * FROM products JOIN product_details ON products.id=product_details.p_id WHERE product_details.lang_id=".$ld." AND  products.published='Yes' AND product_details.name LIKE '%".$keyword."%'";

//"select topictitle,topicdescription from topics where topictitle like '%$keyword%' or topicdescription like '%$keyword%'";

//echo $query;
$result = mysqli_query($dbc,$query);
if($result){
    if(mysqli_affected_rows($dbc)!=0){
          while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
     echo '<p> <b><a href="http://www.wines2u.gr/view_product/'.$row['p_id'].'">'.$row['name'].'</b></a>'.$row['price'].'</p>'   ;
    }
    }else {
        echo 'No Results for :"'.$_GET['term'].'"';
    }
  
}
}else {
    echo 'Parameter Missing';
}




?>