将 $_POST 添加到 FPDF 文件,或将数据库连接到 FPDF?

发布于 2024-10-10 15:39:23 字数 689 浏览 0 评论 0原文

我想这样做:

当用户编辑一些文本并单击“提交 - for html”时,将 $_post 信息放入 FPDF 文件中。

我被困在这里:

<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->AddPage();
$pdf->Cell(60,10,'Powered by FPDF.',0,1,'C');

$pdf-> Output();
?>

如何添加 $_POST 属性?如果我这样做,就会出错。

或者,如果有人知道连接到数据库并显示表中信息的方法......那就太好了。

我发现的例子:

$query = "SELECT imageField FROM yyy WHERE ...";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$image = $row['imageField'];

$pdf->MemImage($image, 50, 30);

显然这是一个图像......它怎么能用文本来完成?

I want to do this:

When user edits some text and clicks submit - for html to $_post the info into a FPDF file.

I'm stuck here:

<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->AddPage();
$pdf->Cell(60,10,'Powered by FPDF.',0,1,'C');

$pdf-> Output();
?>

How can I add a $_POST attribute? If I do, it gives an error.

Or if someone knows a way to connect to the database and display info from tables... that would be nice.

Example I found:

$query = "SELECT imageField FROM yyy WHERE ...";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$image = $row['imageField'];

$pdf->MemImage($image, 50, 30);

Obviously that is an image... how can it be done with text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-10-17 15:39:23

我假设您正在复制并粘贴代码片段以使事情正常工作。假设您将 post 变量“name”设置为“MyName”,那么您可以通过将其与传递给函数的字符串联系来打印它:

$pdf->Cell(40,10,'Hello World - '.$_POST[name]);

这会将“Hello World - MyName”打印到 PDF 文件。

要连接到 MYSQL 数据库,您需要以下语句:

mysql_connect('localhost','username','password');  //Replace 'username' and 'password' by your mysql username and password

mysql_select_db('db');  //Replace 'db' by the name of the database

现在进行 SQL 查询以从表 table 中选择字段 fieldname > 在上面提到的数据库 db 中。 条件决定选择哪些行。如果将条件保留为 1,则选择所有行。您可以使用类似 field2='somevalue' 的条件来仅选择 field2 值为 somevalue 的行。

$query=mysql_query("SELECT *fieldname* FROM table WHERE condition "); 

要检索结果,请使用函数 mysql_fetch_assos():

$row_array= mysql_fetch_assos($query);

mysql_fetch_assos() 返回一个包含特定行的字段值的关联数组,并将资源指针移动 1。

$field_value=$row_array['field2'];

I'm assuming you are copying and pasting code snippets to make the thing work. Suppose the post variable 'name' is set to 'MyName' by you, then you can print it by contactinating it with the string you pass to the function :

$pdf->Cell(40,10,'Hello World - '.$_POST[name]);

This would print 'Hello World - MyName' to the PDF file.

To connect to a MYSQL database, you need the following statements:

mysql_connect('localhost','username','password');  //Replace 'username' and 'password' by your mysql username and password

mysql_select_db('db');  //Replace 'db' by the name of the database

Now make the SQL query to select the field fieldname from the table table in the database db mentioned above. The condition decides which rows are selected. If you keep condition as 1, all rows are selected. You can use a condition like field2='somevalue' to select only those rows where the value of field2 is somevalue.

$query=mysql_query("SELECT *fieldname* FROM table WHERE condition "); 

To retrieve the result use the function mysql_fetch_assos():

$row_array= mysql_fetch_assos($query);

mysql_fetch_assos() returns an assosiative array containing the field values of a particular row and moves the resource pointer by one.

$field_value=$row_array['field2'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文