-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
40 lines (36 loc) · 998 Bytes
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
include 'DBconnection.php';
//$barcode=$_POST['barcode'];
extract($_POST);
$qty = 1;
if(strpos($t,'*') !== false){
$ex = explode("*",$t);
$term = (isset($ex[1]))? $ex[1] : "";
$qty = $ex[0];
}else{
$term = $t;
}
$sql="SELECT * FROM `products` WHERE `barcode` LIKE '%{$term}%'";
$result=mysqli_query($conn,$sql);
$num=mysqli_num_rows($result);
$data = array();
if($num>0){
//case if barcode exists in product table in database
while($row=mysqli_fetch_assoc($result)){
$row['qty']=1;
$data[] = array("label"=>$row['barcode']." - ".$row['prodName'],
"value"=>$row['barcode'],
"id"=>$row['prodID'],
"data"=>$row
);
}
}
else{
//case if barcode doesnot exists in product table in database
$data[] = array("label"=>"Product Code is Unknown.",
"value"=>"",
"id"=>""
);
}
echo json_encode($data);
?>