Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "config.php";
- $request = $_POST['request']; // request
- // Get product_name list
- if($request == 1){
- $search = $_POST['search'];
- $query = "SELECT * FROM products WHERE product_name like'%".$search."%'";
- $result = mysqli_query($con,$query);
- while($row = mysqli_fetch_array($result) ){
- $response[] = array("value"=>$row['ID'],"label"=>$row['product_name']);
- }
- // encoding array to json format
- echo json_encode($response);
- exit;
- }
- // Get details
- if($request == 2){
- $userid = $_POST['userid'];
- $sql = "SELECT * FROM products WHERE ID=".$userid;
- $result = mysqli_query($con,$sql);
- $users_arr = array();
- while( $row = mysqli_fetch_array($result)){
- $userid = $row['ID'];
- $fullname = $row['product_number'];
- $categorie_number = $row['IDCategorie'];
- //$users_arr[] = array("id" => $userid, "product_number" => $fullname);
- }
- $sql = "SELECT categories_name, categories_number FROM categories WHERE categories_number=".$categorie_number;
- $result = mysqli_query($con,$sql);
- while( $row = mysqli_fetch_array($result)){
- $categorie_name = $row['categories_name']." ".$row['categories_number'];
- // $users_arr[] = array("id" => $userid, "product_number" => $fullname, "categories_name" => $categorie_name);
- }
- // $sql = $sql = "SELECT SUM(amount_in) AS totalIn, SUM(amount_out) AS totalOUT FROM inventory_stock WHERE product_number=".$fullname;
- $sql = "SELECT ID, SUM(amount_in) AS totalIn, SUM(amount_out) AS totalOUT FROM inventory_stock WHERE product_number='$fullname'";
- $result = mysqli_query($con,$sql);
- while ($row = mysqli_fetch_assoc($result)){
- //$totalIn = $row['totalIn'];
- //$totalOUT = $row['totalOUT'];
- $inventory_stockID = $row['ID'];
- $totalstock = $row['totalIn'] - $row['totalOUT'];
- $users_arr[] = array("id" => $userid, "product_number" => $fullname, "categories_name" => $categorie_name, "total_stock" => $totalstock);
- }
- // encoding array to json format
- echo json_encode($users_arr);
- exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement