<?php
 $column = array();
 $data = array();
 $index = array();
 $stock_id = $_GET['stock_id'];

$mysqli = new mysqli("localhost","root","","inspection");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}else{


     $update = "SELECT `Front_bumper`, `Left_headlamp`, `Right_headlamp`, `Front_grill`,
      `Front_bonnet`, `Front_glass`, `Right_front_door_glass`, `Right_rare_door_glass`,
       `Left_front_door_glass`, `Left_rare_door_glass`, `Roof`, `Rare_glass`, `Back_door`,
       `Left_taillamp`, `Right_taillamp`, `Rare_bumper`,
     `Right_front_tire`, `Right_front_fender`, `Right_front_door`,
      `Right_rare_door`, `Right_rare_fender`, `Right_rare_tire`,
      `Left_front_tire`, `Left_front_fender`, `Left_front_door`, `Left_rare_door`,
      `Left_rare_fender`, `Left_rare_tire`, `Engine_room`, `Stock_id`
      from inspection_cars WHERE Stock_id = $stock_id";

      $result = $mysqli->query($update);

      while($row = mysqli_fetch_array($result)){

         
        $data[] = array_filter($row);


        //print_r(array_filter($row));

     }






    //  $notNullArray = array_filter($column[0],'strlen');
    //  while ($ArrayValues = current($notNullArray)) {
    //   $index [] = key($notNullArray);
    //   next($notNullArray);
    //
    //
    // }
    //
     //  for($i=0;$i<count($data);$i++){
     //    $mark=explode(',', $data[$i]);
     //     foreach($mark as $out) {
     //      echo $out;
     //   }
     //
     // }



    // for($i=1;$i<count($data);$i++){
    //
    //     $query = "SELECT * FROM `inspection_description` WHERE  id IN '$data[$i]'  ORDER BY `Category`";
    //     $resultGetAllData = $mysqli->query($query);
    //       while($rowData = mysqli_fetch_assoc($resultGetAllData)){
    //
    //         print_r($rowData);
    //
    //         $data[] = array('id'=>$rowData['id'],
    //           'Desc'=>$rowData['Flaw Description'],
    //           "Category" => $rowData['Category'] ) ;
    //
    //
    //
    //     }
    //
    // }

    foreach($data as $key=>$row) {
   	$data[$key]=array_map(
   		function($el){
   			return explode(',',$el);
   		},$row);
   }

       returnJSON($data);


}


function returnJSON($dataReturn){

 $json = json_encode($dataReturn);
 echo $json;
}


?>
