使用fpdf在pdf上从php中的Mysql获取数据
我是php新手,第一次使用FPDF生成pdf文件。使用fpdf在pdf上从php中的Mysql获取数据,php,html,mysql,pdf,fpdf,Php,Html,Mysql,Pdf,Fpdf,我是php新手,第一次使用FPDF生成pdf文件。 我有一个名为test123的数据库和名为form的表,其中有四个字段 id数据类型为int, 数据类型为Varchar的名称,地址和名称,最后一个是数据类型为longblob的文本 由具有textarea的窗体插入这些字段的数据 问题是,当我想生成pdf文件并从数据库导入数据时,数据类型blob并没有转换。这是我问题的截图,点击链接即可/ 下面是我正在使用的代码: <?php require('fpdf/fpdf.php'); //c
我有一个名为
test123
的数据库和名为form
的表,其中有四个字段
id
数据类型为int,
数据类型为Varchar的名称
,地址
和名称
,最后一个是数据类型为longblob的文本
由具有textarea的窗体插入这些字段的数据
问题是,当我想生成pdf文件并从数据库导入数据时,数据类型blob并没有转换。这是我问题的截图,点击链接即可/
下面是我正在使用的代码:
<?php
require('fpdf/fpdf.php');
//create a FPDF object
$pdf=new FPDF();
//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
//$pdf->SetTextColor(50,60,100);
//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode('default');
//insert an image and make it a link
$pdf->Image('image/logo.gif',100,10,20,0);
//display the title with a border around it
$pdf->SetXY(40,30);
$pdf->SetDrawColor(50,60,100);
$pdf->Write(10,'The Pakistan Credit Rating Agency Limited',0,'C',0);
$pdf->Line(10,40,200,40);
//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (20,45);
$pdf->SetFontSize(10);
$pdf->SetTextColor(30,30,100);
$pdf->Write(5,'NL FYI s-l4l (PSO-040515)');
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test123"; // Database name
$tbl_name="form"; // Table name
$con = mysqli_connect('localhost','root','');
mysqli_select_db($con,"test123");
$sql="SELECT * FROM form WHERE id = '30'";
$result = mysqli_query($con,$sql);
while($rows= (mysqli_fetch_array($result,MYSQLI_ASSOC)))
{
$name = $rows['Name'];
$address = $rows['Address'];
$class = $rows['Designation'];
$phone = $rows['Text'];
$pdf->SetXY (20,60);
$pdf->SetFontSize(12);
$pdf->SetTextColor(0,0,0);
$pdf->Write(7,$name);
$pdf->SetXY (20,65);
$pdf->Write(7,$address);
$pdf->SetXY (20,70);
$pdf->Write(7,$class);
$pdf->SetXY (20,90);
$pdf->Write(7,$phone);
$pdf->Ln();
}
//Output the document
$pdf->Output('test.pdf','I');
?>
$phone=$rows['Text']$text=$row['text'];为什么在不同的while循环中使用测试列两次???@habibulhaq i remove$text=$row['text'];但是它还不起作用。看看这个,你的$_行['Text']是用->Write()输出的html代码。您需要使用->WriteHTML()的扩展版本,例如,您可以使用@habibulhaq亲爱的,我不理解这个主题,这里给出的标记在我的cae中不起作用:(DBController只是一个函数。
$s = oci_parse($conn,"SELECT * FROM form WHERE id = '30'");
oci_execute( $s);
$result = array();
while ($row = oci_fetch_array( $s, OCI_ASSOC+OCI_RETURN_NULLS)) {
$result[] = $row; }
$pdf->Cell(20,5,'Name',1,0,'C',0);
$pdf->Cell(20,5,$result[]['Name'],1,0,'C',0);
$pdf->Output();
header("Content-Disposition: attachment; filename=filename.pdf");
<?php
require("DB.php");
$db_handle = new DBController();
$result = $db_handle->runQuery("SELECT * FROM student");
$header = $db_handle->runQuery("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='blog'
AND `TABLE_NAME`='student'");
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
foreach($header as $heading) {
foreach($heading as $column_heading)
$pdf->Cell(90,12,$column_heading,1);
}
foreach($result as $row) {
$pdf->SetFont('Arial','',12);
$pdf->Ln();
foreach($row as $column)
$pdf->Cell(90,12,$column,1);
}
$pdf->Output();
?>