query('SELECT projectname, clientprogress, client FROM projects'); $projectNames = []; while ($row2 = $result2->fetchArray()) { if ($selectedName == $row2['client']) { $projectId = explode("«", $row2['clientprogress']); $projectNames[] = $projectId[2] . "," . $row2['projectname']; } } // Close the database connection $db2->close(); // Return the project names as a JSON response $data = [ 'projectnames' => $projectNames ]; // Set the response Content-Type header('Content-Type: application/json'); // Return the data as JSON response echo json_encode($data); } else { http_response_code(400); // Bad Request echo json_encode(['error' => 'Invalid request']); } ?>