我正在尝试将 MySQL 数据库中的一些数据写入 txt 文件。目前我将它放在 html 的文本区域标签中,但我似乎无法将它放入 txt 文件中。这是我作为textarea得到的:
$pairresult = mysqli_query($conmysql,"SELECT * FROM orders WHERE order_number IN ( SELECT order_number FROM orders GROUP BY order_number HAVING count(ordern_number) > 1 ) ORDER BY order_number");
echo "<h4>Customers with Multiple Orders</h4><textarea rows=\"5\" cols=\"90\" readonly>";
while($row = mysqli_fetch_array($pairresult))
{
echo str_replace("&","\&",$row['shipment_address_name']) . "\n";
echo str_replace("&","\&",$row['shipment_address_street']) . "\n";
if ( !empty($row['shipment_address_street_2']) ) {
echo str_replace("&","\&",$row['shipment_address_street_2']) . "\n";
} else {
}
echo str_replace("&","\&",$row['shipment_address_city']) . "\n";
echo str_replace("&","\&",$row['shipment_address_postal_code']) . "\n";
if ( !empty($row['customer_phone']) ) {
echo str_replace("&","\&",$row['customer_phone']) . "\n";
} else {
}
echo "(" . $row['fulfillment_line_item_id'] . ")\n";
echo "[" . $row['item_name'] . "]\n\n";
}
echo "</textarea><br />";
我在脚本的另一部分有类似的内容,但没有成功写入 txt 文件的 if 语句等:
$pairresult = mysqli_query($conmysql,"SELECT * FROM orders WHERE order_number IN ( SELECT order_number FROM orders GROUP BY order_number HAVING count(order_number) > 1 ) ORDER BY order_number");
while($row = mysqli_fetch_array($pairresult))
{
$multiple = "productmultiple_tracking($filetimestamp).csv";
$handle = fopen($grouponmultiple, 'a') or die('Cannot open file: '.$multiple);
$data = "\"" . $row['fulfillment_line_item_id'] . "\",\"" . $row['fulfillment_line_item_id'] . "\",\"YDL\",\"\"\n";
fwrite($handle, $data);
fclose($handle);
}
echo "<a href=\"$multiple\">Download Template</a><br />";
我如何将 textarea 中的那个位以相同的格式保存到 txt 文件中?