<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
 $tbl="partmaster";

if(@$_GET['type']=='name')
{
$partname=$_GET['key'];


$re=mysqli_query($db,"select a.partcode,a.partname,a.reordlevel,a.cost from $tbl a, where a.partname like '%$partname%'  order by a.partcode desc  limit 10");


}

elseif(@$_GET['type']=='service')
{
$service=$_GET['key'];


$re=mysqli_query($db,"select labname,hrrate from labourmaster where labname like '%$service%' limit 10");


}


else
{
$partcode=$_GET['key'];
$re=mysqli_query($db,"select a.partcode,a.partname,a.reordlevel,a.cost from $tbl a where a.partcode like '%$partcode%' order by a.partcode desc  limit 10");

}
$json="";
while($row=mysqli_fetch_array($re))
{

	 $json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","supqty":"'.addslashes($row[2]).'","price":"'.addslashes($row[3]).'"},';

}

echo '['.trim($json,',').']';

?>
