Halo master, newbie numpang tanya.
Ane kan dapet tugas untuk bikin pdf dari html/php. Bikin pdfnya untuk kartu tanda ujian seleksi masuk di suatu sekolah.
Ane bikin webnya pake dreamweaver, dan untuk pdfnya udah bikin pake FPDF.
Tapi ketika dimasukkan record dari MySQL. terjadi error seperti ini
Notice: Undefined variable: row_Recordset1 in C:\xampp\htdocs\new\print3.php on line 103
FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\new\print3.php:103)
<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = "SELECT * FROM tanggal WHERE tanggal_id = 1";
$Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_localhost, $localhost);
$query_Recordset2 = "SELECT * FROM `user` WHERE userID = 15";
$Recordset2 = mysql_query($query_Recordset2, $localhost) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NEW PDF</title>
</head>
<body>
<?php
ob_end_clean();
require ('fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('logo2.png',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(95);
// Title
$this->Cell(30,10,'SMA X KOTA X',0,0,'C');
// Line break
$this->Ln(8);
// Arial bold 15
$this->SetFont('Arial','B',10);
// Move to the right
$this->Cell(95);
// Title
$this->Cell(30,10,'Jalan X Kecamatan X Kota X',0,0,'C');
// Line break
$this->Ln(6);
// Arial bold 15
$this->SetFont('Arial','B',10);
// Move to the right
$this->Cell(95);
// Title
$this->Cell(30,10,'Telp : (XXX) XXXXXXX | Fax : (XXX) XXXXXXX | E-mail :
XXXXXX@gmail.com',0,0,'C');
// Line break
$this->Ln(15);
// Arial bold 15
$this->SetFont('Arial','B',10);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,'KARTU TANDA PESERTA',0,0,'C');
// Line break
$this->Ln(6);
// Arial bold 15
$this->SetFont('Arial','B',10);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,'PENERIMAAN SISWA BARU SMA X',0,0,'C');
// Line break
$this->Ln(6); // Arial bold 15
$this->SetFont('Arial','B',10);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,'TANGGAL UJIAN : '
.$row_Recordset1['tanggal'],0,0,'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-20);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Cetaklah kartu tanda peserta ini menggunakan printer berwarna',0,0,'L');
// Line break
$this->Ln(6);
// Arial bold 15
$this->SetFont('Arial','I',8);
// Move to the right
//$this->Cell(95);
// Title
$this->Cell(0,10,'Ketika ujian, anda perlu membawa kartu tanda peserta ini dan alat tulis',0,0,'L');
}
}
// Instanciation of inherited class
$pdf = new PDF('L', 'mm', 'A5');
$pdf->AliasNbPages();
$pdf->AddPage();
// Logo
$pdf->Image('foto.png',10,66,30);
$pdf->SetFont('Times','',12);
$pdf->Cell(35);
$pdf->Cell(0,10,'Nama : '
.$row_Recordset2['name'],0,1);
$pdf->Ln(3);
$pdf->SetFont('Times','',12);
$pdf->Cell(35);
$pdf->Cell(0,10,'No. Peserta : '
.$row_Recordset2['userID'],0,1);
$pdf->Output();
?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
*yang merah itu yang bikin error, padahal itu record yang mau dimasukkan ke dalam kartu ujian.
ada yang bisa ngasih masukan supaya pdfnya bisa memuat hasil query? ane bingung mau tanya dimana lagi. udah liat forum2 diluar tapi kok kurang jelas. makasih banget master2