从数据库中获取数据时,Array_push()在while循环中不起作用

Am having this problem that I have never experienced before. php array_push does not work in while loop. When I use while loop nothing is printed on the browser but when I fetch data without while loop, it's working fine. Where could I be going wrong. I have struggled it seems not to work.

This is my php code:

function getFeaturedCrops(){
    require "config.inc.php";

    try{



        $query = $conn->prepare("SELECT * FROM crops WHERE category = ? "); 
        $query->bindValue(1, 1); 
        $query->execute(); 
        if($query->rowCount()){
            //echo "nice";

            $jsonArray = array();

            while($data = $query->fetch(PDO::FETCH_ASSOC)){
                // here we are loading either animals ar crops

                $type = $data['type'];
                $name = $data['name']; 
                $description = $data['description']; 
                $image = $data['image'];
                $id = $data['salt'];

                if(strlen($description) > 50){
                    $shortDescription = substr($description, 0, 50)."...";
                } else {
                    $shortDescription = $description; 
                }


                if(strlen($name) > 20){
                    $shortName = substr($name, 0, 20)."..."; 
                } else {
                    $shortName = $name;
                }

                if(strlen($type) > 20){
                    $shortType = substr($type, 0, 20)."...";
                } else {
                    $shortType = $type;
                }

                //echo "$shortDescription
"; 

                array_push($jsonArray,
                    array(
                        "type" => $type, 
                        "shortType" => $shortType,
                        "name" => $name, 
                        "shortName" => $shortName, 
                        "description" => $description, 
                        "shortDescription" => $shortDescription, 
                        "image" => $image,
                        "id" => $id,
                        "success" => true
                        )
                    );

            }

        } else {

                array_push($jsonArray, array(
                        "type" => "default", 
                        "shortType" => "default",
                        "name" => "default", 
                        "shortName" => "default", 
                        "description" => "default", 
                        "shortDescription" => "default", 
                        "image" => "default",
                        "id" => "default", 
                        "success" => false
                    )
                ); 
        }

        //echo "well data";

        echo json_encode(array("Items" => $jsonArray)); 

    }  catch(Exception $e){
        die($e->getMessage());
    }
}

Then this how am calling my function:

getFeaturedCrops();

This is my database screenshotenter image description here