prepare('SELECT address, mobile, email FROM clients WHERE name = :name'); $query->bindValue(':name', $selectedName, SQLITE3_TEXT); $result = $query->execute(); // Check if a row was found if ($row = $result->fetchArray(SQLITE3_ASSOC)) { // Split the address into separate parts $addressParts = explode(', ', $row['address']); // Create a new data array with the split address $data = [ 'address1' => isset($addressParts[0]) ? $addressParts[0] : '', 'address2' => isset($addressParts[1]) ? $addressParts[1] : '', 'address3' => isset($addressParts[2]) ? $addressParts[2] : '', 'address4' => isset($addressParts[3]) ? $addressParts[3] : '', 'mobile' => $row['mobile'], 'email' => $row['email'], ]; // Return the data as JSON header('Content-Type: application/json'); echo json_encode($data); } else { // Handle the case where no data was found http_response_code(404); // Not Found echo json_encode(['error' => 'No data found for the selected client.']); } // Close the database connection $db1->close(); } else { http_response_code(400); // Bad Request echo json_encode(['error' => 'Invalid request']); } } else { http_response_code(400); // Bad Request echo json_encode(['error' => 'Invalid request']); } ?>