query($query); while ($row = $result->fetch_assoc()) { fputcsv($output, array( $row['name'], $row['phone'], number_format($row['rate_tilapia'], 2), number_format($row['rate_small_fish'], 2), number_format($row['rate_big_fish'], 2), number_format($row['delivery_rate'], 2), number_format($row['harvesting_fee_tilapia'], 2), number_format($row['harvesting_fee_small_fish'], 2), number_format($row['harvesting_fee_big_fish'], 2) )); } fclose($output); $conn->close(); } catch (Exception $e) { header('Content-Type: text/plain'); echo "An error occurred while exporting data."; error_log("Buyer export error: " . $e->getMessage()); } exit(); ?>