为什么我的 php 脚本不能生成整个 word 文档文件?
这是我在 Linux 环境中使用的 php 脚本:
<?php
include("../_inc/odbcw.php"); //connect string
$cat = $_GET["cat"];
if($_GET["st"]){$crs_query = "select crs_no, title, credits, abstr, prereq, coreq, lab_fee from xxx where active = 'Y' and cat = '".$cat."' and spec_top = 'Y' and prog='UNDG' order by crs_no";}
else {$crs_query = "select crs_no, title, credits, abstr, prereq, coreq, lab_fee from xxx where active = 'Y' and cat = '".$cat."' and prog='UNDG' order by crs_no";}
$crs_result = @mysql_query($crs_query);
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=cat.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo '<table border=0 width = 700>';
if($_GET["st"]){echo '<tr><td><font face=arial size=2><center>CATALOGUE<br>COURSE DESCRIPTIONS - '.$cat.'<br>SPECIAL TOPICS</center></font></td></tr>';}
else {echo '<tr><td><font face=arial size=2><center>CATALOGUE<br>COURSE DESCRIPTIONS - '.$cat.'</center></font></td></tr>';}
echo '</table>';
echo '<hr width=700>';
while($row = mysql_fetch_array($crs_result))
{
$crs_no = $row['crs_no'];
$title = $row['title'];
$credits = $row['credits'];
$abstr = $row['abstr'];
$prereq = $row['prereq'];
$coreq = $row['coreq'];
$lab_fee = $row['lab_fee'];
$rowspan = 2;
if($prereq) {$rowspan++;}
if($coreq) {$rowspan++;}
if($lab_fee=="Y") {$rowspan++;}
echo "<table border=0 width = 700>";
echo "<tr>";
echo "<td rowspan=".$rowspan." valign=top width=100><font face=arial size=2>".$crs_no."</font></td>";
echo "<td valign=top><font face=arial size=2><u>".$title."</u></font></td> <td valign=top align=right><font face=arial size=2>".$credits."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2 valign=top align=justify><font face=arial size=2>".$abstr."</font></td>";
echo "</tr>";
if($prereq)
{
echo "<tr>";
echo "<td colspan=2 valign=top><font face=arial size=2>Prerequisite: ".$prereq."</font></td>";
echo "</tr>";
}
if($coreq)
{
echo "<tr>";
echo "<td colspan=2 valign=top><font face=arial size=2>Coerequisite: ".$coreq."</font></td>";
echo "</tr>";
}
if($lab_fee=="Y")
{
echo "<tr>";
echo "<td colspan=2 valign=top><font face=arial size=2>Lab Fee Required</font></td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
}
echo "</body>";
echo "</html>";
?>
在包含以下内容之前一切正常:
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=cat.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
这些行成功地打开了打开或保存 cat.doc 的对话框,但在我打开它之后,打印的唯一行是:
CATALOGUE
COURSE DESCRIPTIONS -
和此回显文本下方的
。 while 循环回显部分似乎在午休。
有什么想法吗?
Here's the php script I'm using on a linux environment:
<?php
include("../_inc/odbcw.php"); //connect string
$cat = $_GET["cat"];
if($_GET["st"]){$crs_query = "select crs_no, title, credits, abstr, prereq, coreq, lab_fee from xxx where active = 'Y' and cat = '".$cat."' and spec_top = 'Y' and prog='UNDG' order by crs_no";}
else {$crs_query = "select crs_no, title, credits, abstr, prereq, coreq, lab_fee from xxx where active = 'Y' and cat = '".$cat."' and prog='UNDG' order by crs_no";}
$crs_result = @mysql_query($crs_query);
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=cat.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo '<table border=0 width = 700>';
if($_GET["st"]){echo '<tr><td><font face=arial size=2><center>CATALOGUE<br>COURSE DESCRIPTIONS - '.$cat.'<br>SPECIAL TOPICS</center></font></td></tr>';}
else {echo '<tr><td><font face=arial size=2><center>CATALOGUE<br>COURSE DESCRIPTIONS - '.$cat.'</center></font></td></tr>';}
echo '</table>';
echo '<hr width=700>';
while($row = mysql_fetch_array($crs_result))
{
$crs_no = $row['crs_no'];
$title = $row['title'];
$credits = $row['credits'];
$abstr = $row['abstr'];
$prereq = $row['prereq'];
$coreq = $row['coreq'];
$lab_fee = $row['lab_fee'];
$rowspan = 2;
if($prereq) {$rowspan++;}
if($coreq) {$rowspan++;}
if($lab_fee=="Y") {$rowspan++;}
echo "<table border=0 width = 700>";
echo "<tr>";
echo "<td rowspan=".$rowspan." valign=top width=100><font face=arial size=2>".$crs_no."</font></td>";
echo "<td valign=top><font face=arial size=2><u>".$title."</u></font></td> <td valign=top align=right><font face=arial size=2>".$credits."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2 valign=top align=justify><font face=arial size=2>".$abstr."</font></td>";
echo "</tr>";
if($prereq)
{
echo "<tr>";
echo "<td colspan=2 valign=top><font face=arial size=2>Prerequisite: ".$prereq."</font></td>";
echo "</tr>";
}
if($coreq)
{
echo "<tr>";
echo "<td colspan=2 valign=top><font face=arial size=2>Coerequisite: ".$coreq."</font></td>";
echo "</tr>";
}
if($lab_fee=="Y")
{
echo "<tr>";
echo "<td colspan=2 valign=top><font face=arial size=2>Lab Fee Required</font></td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
}
echo "</body>";
echo "</html>";
?>
Everything works fine before the inclusion of:
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=cat.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
These lines successfully bring up the dialogue box to open or save cat.doc, but after I open it, the only lines printed are:
CATALOGUE
COURSE DESCRIPTIONS -
and the <HR>
beneath this echoed text. It seems to go on lunch break for the while loop echoing section.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$cat
没有任何值,除非它是在“../_inc/odbcw.php”
中定义的。$cat
has no value, unless it is defined in"../_inc/odbcw.php"
.