Ho provato con questo codice


ma mi registra solo l'ultimo utente sul file

codice:
// Create connection$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT i.emailaddress, d.openip FROM email_list_subscribers i, email_stats_emailopens d where i.subscriberid = d.subscriberid";
$result = $conn->query($sql);


if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
			$file = fopen("test8.txt", "w");
			$utenti = "<br> id: ". $row["subscriberid"]. " - Name: ". $row["emailaddress"]. " " . $row["openip"] . "<br>";
			echo fwrite($file,$utenti);
       
     }
} else {
     echo "0 results";
}
fclose($file);