0

我在内联 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)

它不工作。这段代码有什么问题?提前致谢。

4

1 回答 1

1

我不确定您的示例代码是否都是内联脚本的一部分,或者您是否从流程的不同部分选择了代码。我猜你为了简洁起见试图简化你的样本。因此,我假设您的流程类似于以下内容。

你的 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>

(如果您填写示例代码,我会更新答案。)

于 2013-07-22T14:46:10.303 回答