<?php
include('config.php');

$q 		= strtolower($_GET["q"]);

if (!$q) return;


$sqlprod = "SELECT *, COUNT(*) as num FROM mst_product where pm_barcode = '$q'";
$prod_conn = $conn->query($sqlprod);
$prod = $prod_conn->fetch_assoc();
$num = $prod['num'];

if($num==1){
		$name 				= ($prod['pm_name']);
		$product_id 		= ($prod['pm_autoid']);
		$product_name 		= ($prod['pm_name']);
		$bprice 			= $prod['pm_bprice'];
		$pm_ums 			= $prod['pm_ums'];
		echo "$name|$product_id|$product_name|$bprice|$pm_ums|$num \n";	
	}else{

$sqlprod = "SELECT * FROM mst_product where (pm_name LIKE '%$q%' or pm_code LIKE '%$q%' or pm_barcode LIKE '%$q%')  LIMIT 0,300";
$prod_conn = $conn->query($sqlprod);
while($prod = $prod_conn->fetch_assoc()){
	
		$name 				= ($prod['pm_name']);
		$product_id 		= ($prod['pm_autoid']);
		$product_name 		= ($prod['pm_name']);
		$bprice 			= $prod['pm_bprice'];
		$pm_ums 			= $prod['pm_ums'];
		echo "$name|$product_id|$product_name|$bprice|$pm_ums|$num \n";
}
		
		}


?>