我在嵌入式PHP中的查询:
$sql='select * from tbl_1 where id=1';
$res=mysql_query($sql);
$row=mysql_fetch_assoc($res);
$some_value = $row['s_code'];
$text = $some_value;
$pdf->text($w / 1.2 - $width / 2,40, $text, $font, $size, $color);(this is a piece of code from footer)
它不起作用。此代码有什么问题?提前致谢。
我不确定您的示例代码是否全部都是内联脚本的一部分,或者您是否从流程的不同部分中选择了代码。我猜您为简洁起见试图简化样本。因此,我假设您的流程与以下内容类似。
您的PHP脚本:
$sql='select * from tbl_1 where id=1';
$res=mysql_query($sql);
$row=mysql_fetch_assoc($res);
$some_value = $row['s_code'];
$dopmdf = new DOMPDF;
// etc.
您的HTML文档:
<html><body>
<script type="text/php">
// populate $w, $width, $font, $size, $color, then ...
$text = $some_value;
$pdf->text($w / 1.2 - $width / 2,40, $text, $font, $size, $color);
</script>
<p>some text</p>
...
</body></html>
内联脚本在与主要PHP脚本中的代码不同的上下文中运行。因此,如果您正在执行此操作,则需要使用$GLOBALS
变量而不是直接引用,即
您的HTML文档:
<html><body>
<script type="text/php">
// populate $w, $width, $font, $size, $color, then ...
$pdf->text($w / 1.2 - $width / 2,40, $GLOBALS['some_value'], $font, $size, $color);
</script>
<p>some text</p>
...
</body></html>
(如果您填写示例代码,我将更新答案。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句