修改代码
<?php
require_once("dompdf/dompdf_config.inc.php");
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
echo "<h1><center>order status </center></h3>";
include("../../../../../../../inetpub/wwwroot/dbcon/connection.php");
$content="";
if(isset($_POST['submit']))
{
include("../../../../../../../inetpub/wwwroot/dbcon/connection.php");
$content .= "<h3>Customer order</h3>";
$search=htmlspecialchars($_POST['search']);
$selectcondition = "SELECT * FROM customer.order where DATE='".$search."'";
$check=mysql_query($selectcondition,$con);
$fetch=mysql_fetch_row($check);
if(!$fetch)
{
$content .= "<font color='red'>";
$content .= "<br>";
$content .= "No order Found In The Database";
$content .= "<br>";
$content .= "</font>";
return $content;
}
else //if the above condition is flase !
{
$sql= "select * from customer.order where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
$content .= "<table class='mytable' width='100%' height='10%' border='1' cellspacing='0'>
<tr>
<th>DATE</th>
<th>ORDER</th>
<th>CUSTNAME</th>
<th>COMMENTS</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
$content .= "<tr>";
$content .="<td>" . $records['TIMESTAMPS'] . " </td>";
$content .= "<td>" . $records['ORDER']. " </td>";
$content .= "<td>" . $records['CUSTNAME'] . " </td>";
$content .="<td align='center'>";
$content .= '<textarea name="textarea" cols="100" >'.$records['COMMENTS'].'</textarea><br>';
$content .= "</td>";
}
"</table>";
}
}
$html= $content;
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("order.php");
?>
我已根据最近的更改修改了我的代码,我删除了内容功能并将所有内容都包含在 $ content 变量中。
之后生成损坏的PDF。 请帮我解决这个问题。
再次感谢您的回复。
答案 0 :(得分:0)
你错了
$dompdf->load_html($html);
根据docs
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
并且您始终使用echo来输出内容。尝试首先创建对象,然后return
,所以它确实存在于变量:)中,没有回声,它们应该可以工作。
所以你的代码看起来像这个fx ::
if(isset($_POST['submit'])){
include("../../../../../../../inetpub/wwwroot/dbcon/connection.php");
$content = "<h3>Turnover For Apria</h3>";
$search=htmlspecialchars($_POST['search']);
$selectcondition = "SELECT * FROM customer.order where DATE='".$search."'"; //Select Query Which check the whether the TURNOVER for the given INCIDENT is exit or not.
$check=mysql_query($selectcondition,$con);
$fetch=mysql_fetch_row($check);
if(!$fetch) //If checklist for the given date is not exit execute if condition
{
$content .= "<font color='red'>";
$content .= "<br>";
$content .= "No records Found In The Database";
$content .= "<br>";
$content .= "</font>";
return $content;
}
所以创建一个变量,将html附加到它并在每次需要时将其返回。应该工作
我想这会做,测试并让我知道::::
<?php
require_once("dompdf/dompdf_config.inc.php");
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
echo "<h1><center>Midrange, Turnover For All The Accounts </center></h3>";
//include("../../../../../../../inetpub/wwwroot/dbcon/connection.php");
//WHY DO YOU NEED THIS TO BE TWICE?
function content()
{
//init the content variable
$content = null;
if(isset($_POST['submit']))
{
include("../../../../../../../inetpub/wwwroot/dbcon/connection.php");
$content .= "<h3>Turnover For Apria</h3>";
$search=htmlspecialchars($_POST['search']);
$selectcondition = "SELECT * FROM customer.order where DATE='".$search."'"; //Select Query Which check the whether the TURNOVER for the given INCIDENT is exit or not.
$check=mysql_query($selectcondition,$con);
$fetch=mysql_fetch_row($check);
if(!$fetch) //If checklist for the given date is not exit execute if condition
{
$content .= "<font color='red'>";
$content .= "<br>";
$content .= "No records Found In The Database";
$content .= "<br>";
$content .= "</font>";
return $content;
}
else //if the above condition is flase !
{
$sql= "select * from customer.order where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
//$fetch_rows=mysql_fetch_row($mydata);
$content .= "<table class='mytable' width='100%' height='10%' border='1' cellspacing='0'>
<tr>
<th>DATE</th>
<th>ORDER</th>
<th>SUTNAME</th>
<th> COMMENTS</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
$content .= "<tr>";
$content .= "<td>" . $records['TIMESTAMPS'] . " </td>";
$content .= "<td>" . $records['ORDER']. " </td>";
$content .= "<td>" . $records['CUSTNAME'] . " </td>";
$content .= "<td align='center'>";
$content .= '<textarea name="textarea" cols="100" >'.$records['COMMENTS'].'</textarea><br>';
$content .= "</td>";
}
}
$content .= "</table>";
return $content;
}
$html=content();
if($html){
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("order.pdf");
}else{
echo "Look like something is wrong here .";
}
?>
第二次更新
此示例正常运行,请确保您已包含所有正确的文件并修复所有语法错误,例如一个额外的}
也请更改为mysqli_*
<?php
$html=content();
if($html){
require_once("dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("order.pdf");
}else{
echo "Look like something is wrong here .";
}
function content(){
$content = null;
$content .= "<table class='mytable' width='100%' height='10%' border='1' cellspacing='0'>
<tr>
<th>DATE</th>
<th>ORDER</th>
<th>SUTNAME</th>
<th> COMMENTS</th>
</tr>";
$content .= "</table>";
return $content;
}
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
echo "<h1><center>Midrange, Turnover For All The Accounts </center></h3>";
?>
它必须按此顺序处理,因为它必须尊重php中的标题,此示例将生成可以打开的正确pdf,只需要填充正确的数据