2010-05-10 62 views
1

下面是我使用的是Linux环境下的PHP脚本:为什么不能从我的PHP脚本生成整个word doc文件?

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>"; 

这些线成功弹出对话框打开或保存猫:

<?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>"; 

?> 

一切都列入前工作正常.DOC,但之后,我打开它,打印的唯一的线路有:

CATALOGUE 
COURSE DESCRIPTIONS - 

<HR>在这下面呼应文本。它似乎在while循环回显部分的午休时间。

任何想法?

回答

1

$cat没有任何价值,除非它在"../_inc/odbcw.php"中定义。

+0

嗯它在那里,但我想我没有复制到这里。生病编辑帖子 – CheeseConQueso 2010-05-10 17:09:19

+0

虽然这是问题的一部分,所以即将接受这个答案。 $ cat was not coming coming through after I tried to echo out out – CheeseConQueso 2010-05-10 17:13:02

+0

thanks ...不能相信我错过了 – CheeseConQueso 2010-05-10 17:15:07

相关问题