<?php
 
include 'dbconfig.php';
 
// Create connection
$nama=$_POST['nama'];
//$kodecab=$_POST['kodecab'];
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
//$result["errorcode"]="0";
 
$sql = "SELECT id, kode, nama, harga,harga_beli FROM tbl_barang where nama like '%".$nama."%' OR kode like '%".$nama."%' order by id desc";
 
$res = mysqli_query($conn, $sql);


$sqljum =mysqli_query($conn, "SELECT id, kode, nama, harga,harga_beli FROM tbl_barang where nama like '%".$nama."%' OR kode like '%".$nama."%' order by id desc");
$sqljum2=mysqli_num_rows($sqljum);
 
$items = array();
 
if (mysqli_num_rows($res) > 0) {
 
    while($row = mysqli_fetch_object($res)){
 
        array_push($items, $row);
 
//$result["errorcode"] = "1";
 
    $result["data"] = $items;
 
}}
else
{
 
       $result["errormsg"] = "failed";
 
}
 
$result["jum"] = strval($sqljum2);

echo json_encode($result);
 
mysqli_close($conn);
 
?>
