gpt4 book ai didi

mysql - 将 MySQL 数据导出到创建多个页面的 RTF 模板

转载 作者:行者123 更新时间:2023-11-30 23:26:45 25 4
gpt4 key购买 nike

只要我只有 1 行,从数据库中提取的数据就可以毫无问题地插入到 RTF 模板中。但是,如果我将 header("Content-type: text/rtf") 放在循环中,我会收到一个 headers already sent 错误。从代码中删除 header 时,原始数据会在浏览器窗口中正确打印。

如何合并数据库中多个记录的数据以创建多个文档(或 1 个带分页符的文档)?

代码在这里:

$document='../docs/letter.rtf';
$qry="Select * from table";
$result=mysql_query($qry);
$num_row=mysql_num_rows($result);

while($row=mysql_fetch_assoc($result)){
$account_id=$row['pk_account];
$name=$row['first_name'];
$file_doc='01-'.$pk_account.'.rtf';
....

$body=file_get_contents($document);
$body=str_replace("NAME", $name, $body);
....

for($i=0; $i<$num_rows; $i++){
}

header("Content-type: text/rtf");
header("Content-Disposition:attachment; filename={$file_doc}");
echo $body;
}

最佳答案

您需要连接您的 $body。所以不是这个:

$body=file_get_contents($document);
$body=str_replace("NAME", $name, $body);

试试这个:

$body.=str_replace("NAME", $name, file_get_contents($document));

然后把它放在你的 while 循环之外:

header("Content-type: text/rtf");
header("Content-Disposition:attachment; filename={$file_doc}");
echo $body;

关于mysql - 将 MySQL 数据导出到创建多个页面的 RTF 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12922710/

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