dongyinzhi4689 2012-04-09 17:49
浏览 50

导出的RTF文档中的记录未循环

I am exporting content from an MySQL database to a Word Template (RTF) via PHP.

There is a section, "Appendix B", which should display all the Acronyms found for a record. The minimum records to appear for this section is 90 (i.e. these are standard acronyms (tblAcronyms) that each record will have); however the maximum records are unknown since users can add to this listing (tblAppendixB).

The Word (i.e. RTF) document should display all the records found, however, it is only displaying the first record.

This is what I have thus far:

<?php
....

#Retrieve Appendix B records
$qry_get_AppB = "SELECT vAcronym, vAcronymDesc FROM tblAcronyms
                   UNION SELECT vAcronym, vAcronymDesc FROM tblAppendixB
                     WHERE fkID = ". $i_fk_id . " ORDER BY vAcronym ASC";
$qry_appb_result = mysql_query($qry_get_AppB);
$qryAppBno_rows = mysql_num_rows($qry_appb_result);    

//Generate the headers to help a browser choose the correct location
header('Content-Type: application/msword');
header('Content-Disposition: inline; filename="'.$vProgramName.'_rec.rtf");

//Open the template file
$tfilename = 'Appb_Template.rtf';
$fp = fopen($tfilename, 'r');

//Read the template into a variable
$toutput = fread($fp, filesize($tfilename));

fclose($fp);

//Replace the place holders in the template with data
if($qryAppBno_rows > 0)
{
  while($rowAppB = mysql_fetch_array($qry_appb_result)) 
  {
     $vAppB = $rowAppB['vAcronym'] . '-' . $rowAppB['vAcronymDesc'] . "
";
     $toutput = str_replace('<<vAppB>>', $vAppB, $toutput);
  }
}

//Send the generated document to the browser
echo $toutput;

?>

I have searched this forum and others but have yet to find a solution.

Any assistance is greatly appreciated.

  • 写回答

2条回答 默认 最新

  • douyou1937 2012-04-09 17:56
    关注

    Okay, I'm not quite sure what your template looks like, but I guess, you only have 1 place holder named <<vAppB>>. In your 1st iteration (if there is any data available) you replace that placeholder with your 1st data entry. In this fact only one placeholder is shown.

    May rewrite your code to something similar to this

    ... //do your stuff
    $newLine = "
    ";
    $appendix = "";
    while($rowAppB = mysql_fetch_array($qry_appb_result)) {
        $appendix .= $rowAppB['vAcronym'] . '-' . $rowAppB['vAcronymDesc'] . $newLine;
    }
    $toutput = str_replace('<<vAppB>>', $appendix, $toutput);
    ...//do some other stuff
    

    Just simple prototyping, so you may have to do some additional work.

    The trick is to collect all entries you got and than replace it with your placeholder :)

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法