query($sql); if ($result->num_rows > 0) { // Array to hold the results $rows = array(); // Fetch data from each row and add it to the array while($row = $result->fetch_assoc()) { if($row['read_by_user']==0){ $count= $count + 1; } if($count > 0){ $isVisible = 'true'; }else{ $isVisible = ''; } $rows[] = $row; } // Output the result in JSON format header('Content-Type: application/json'); echo json_encode([$rows,"Count" => "$count"]); //echo json_encode(["Count" => "$count","dashBoardView" => "$isVisible"]); } else { echo "0 results"; } } $conn->close(); ?>