gpt4 book ai didi

php - 将大型 mysql 输出加载到变量中以写入文件

转载 作者:行者123 更新时间:2023-11-29 09:22:32 28 4
gpt4 key购买 nike

这是我必须编写文件的代码

<?
$date = date(F jS, Y g:i:s a);
$filename = "$date.csv";
$fh = fopen($filename, 'w') or die("can't open file");
$data = "";
fwrite($fh, $data);
fclose($fh);
?>

我需要写入的数据由 mysql 查询的输出组成,如下所示

echo "<tr>";  
echo "<td valign='top'>" . nl2br( $row['productid']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['user_id']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['category_id']) . "</td>";
echo "<td valign='top'><input type=text value=\"" . nl2br( $row['producttitle']) . "\"></td>";
echo "<td valign='top'>" . nl2br( $row['item_counter_style']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['Quantity']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['payment_gateway']) . "</td>";
echo "<td valign='top'><div id=ddesc>" . nl2br( $row['detailed_descrip']) . "</div></td>";
echo "<td valign='top'>" . nl2br( $row['selling_method']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['min_bid_amount']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['bidincrement']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['shipping_cost']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['who_pay_shipping']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['shipping_route']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['duration']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['currency']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['reserve_price']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['quick_buy_price']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['bid_starting_date']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['start_delay']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['status']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture1']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture2']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture3']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture4']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture5']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture6']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture7']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['picture8']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['payment_name']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['quantity_sold']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['clicks']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['expire_date']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['payment_id']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['size_of_quantity']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['tax']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['sniper']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['no_of_repost']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['sale_price']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['s_repost']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['shop']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['relisted']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['or_price']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['return_pol']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['timetoadd']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['special']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['discount']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['bonus']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['totbid']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['freebids']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['autobidder']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['supplier']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['supplier_cost']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['supplier_item_number']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['supplier_shipping_cost']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['supplier_notes']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['shipping_cost_a']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['shipping_cost_c']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['Auction_ID']) . "</td>";
echo "<td valign='top'><a href=edit.php?productid={$row['productid']}>Edit</a></td><td><a href=delete.php?productid={$row['productid']}>Delete</a></td> ";
echo "<td><input type=submit class=clone value=clone></td></tr>\r\n";
echo "</tr>";

我如何将所有这些(上面)放入 $data 中,以写入我的文件?

最佳答案

将所有这些 echo 替换为 $data .=,然后您就可以开始了。 (当然,您需要将 fwrite()fclose() 调用放在之后)。

<?
$date = date(F jS, Y g:i:s a);
$filename = "$date.csv";
$fh = fopen($filename, 'w') or die("can't open file");
$data = "";

$data .= "<tr>";
$data .= "<td valign='top'>" . nl2br( $row['productid']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['user_id']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['category_id']) . "</td>";
$data .= "<td valign='top'><input type=text value=\"" . nl2br( $row['producttitle']) . "\"></td>";
$data .= "<td valign='top'>" . nl2br( $row['item_counter_style']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['Quantity']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['payment_gateway']) . "</td>";
$data .= "<td valign='top'><div id=ddesc>" . nl2br( $row['detailed_descrip']) . "</div></td>";
$data .= "<td valign='top'>" . nl2br( $row['selling_method']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['min_bid_amount']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['bidincrement']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['shipping_cost']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['who_pay_shipping']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['shipping_route']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['duration']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['currency']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['reserve_price']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['quick_buy_price']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['bid_starting_date']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['start_delay']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['status']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture1']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture2']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture3']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture4']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture5']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture6']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture7']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['picture8']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['payment_name']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['quantity_sold']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['clicks']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['expire_date']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['payment_id']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['size_of_quantity']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['tax']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['sniper']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['no_of_repost']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['sale_price']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['s_repost']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['shop']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['relisted']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['or_price']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['return_pol']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['timetoadd']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['special']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['discount']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['bonus']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['totbid']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['freebids']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['autobidder']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['supplier']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['supplier_cost']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['supplier_item_number']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['supplier_shipping_cost']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['supplier_notes']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['shipping_cost_a']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['shipping_cost_c']) . "</td>";
$data .= "<td valign='top'>" . nl2br( $row['Auction_ID']) . "</td>";
$data .= "<td valign='top'><a href=edit.php?productid={$row['productid']}>Edit</a></td><td><a href=delete.php?productid={$row['productid']}>Delete</a></td> ";
$data .= "<td><input type=submit class=clone value=clone></td></tr>\r\n";
$data .= "</tr>";

fwrite($fh, $data);
fclose($fh);
?>

关于php - 将大型 mysql 输出加载到变量中以写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1229231/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com