<?php  
 include('db_coni.php');  
 $output = '';  
 $type_id = $_POST['type_id'];

 $item_name = $_POST['item_name'];
 if($type_id > 0)
 {
     $sql = "SELECT i.item_id,i.item_name,i.retail_price,t.type_name, i.stock, i.item_cost, i.lp_rate FROM items i, item_type t where t.type_id=i.type_id and i.type_id ='".$type_id."' ORDER BY type_name, item_name";
}else{
       $sql = "SELECT i.item_id,i.item_name,i.retail_price,t.type_name, i.stock, i.item_cost, i.lp_rate FROM items i, item_type t where t.type_id=i.type_id and i.item_name ='".$item_name."' ORDER BY type_name, item_name";
}
 

 $result = mysqli_query($connecti, $sql);  
 $output .= '  
      <div class="table-responsive">  
           <table class="table table-bordered">  
                <tr>  
                     <th width="5%">Id</th>  
                     <th width="25%">Item type</th>  
                     <th width="24%">Description</th>  
                     <th width="12%">Stock</th>                              
                     <th width="12%">Cost</th> 
                     <th width="12%">LP Rate</th> 
                     <th width="12%">Price</th>
                </tr>';  
 $rows = mysqli_num_rows($result);
 if($rows > 0)  
 {  
	 
      while($row = mysqli_fetch_array($result))  
      {  
           $output .= '  
                <tr>  
                     <td>'.$row["item_id"].'</td>  
                     <td class="item_name" data-id1="'.$row["item_id"].'">'.$row["type_name"].'</td>  
                     <td class="brand_name" data-id2="'.$row["item_id"].'">'.$row["item_name"].'</td>  
                     <td class="brand_name" data-id3="'.$row["item_id"].'">'.$row["stock"].'</td> 
                     <td class="item_cost" data-id4="'.$row["item_id"].'">'.$row["item_cost"].'</td>
                     <td class="lp_rate" data-id5="'.$row["item_id"].'" contenteditable>'.$row["lp_rate"].'</td>
                     <td class="retail_price" data-id6="'.$row["item_id"].'" contenteditable>'.$row["retail_price"].'</td>  
                </tr>  
           ';  
      }  
      
 }  
 
 $output .= '</table>  
      </div>';  
 echo $output;  
 ?>