Ruang Web Hosting Indonesia - Solusi Handal, Cepat dan Murah

Archive for April, 2007

php code : generate excel using mysql and php

April 10, 2007 - 3:54 am 2 Comments

just put the header in your php code

<?php
header(”Content-Type: application/vnd.ms-excel”);
header(”Expires: 0″);
header(”Cache-Control: must-revalidate, post-check=0, pre-check=0″);
header(”content-disposition: attachment;filename=form_k01.xls”);

// Make a MySQL Connection
mysql_connect(”172.27.1.245″, “root”, “”) or die(mysql_error());
mysql_select_db(”lp2tk”) or die(mysql_error());

// Get all the data from the “example” table
$result = mysql_query(”SELECT * FROM dat_k01_detail where id_dat=”.$_GET['id_dat'])
or die(mysql_error());

echo “<table border=’1′>”;
echo “<TR><TH rowspan=3>NO.</TH><TH rowspan=3>JABATAN PENGAWAS<BR> KETENAGAKERJAAN</TH><TH colspan=14>JUMLAH</TH><TH rowspan=3>KETERANGAN</TH></TR>
<TR><TH rowspan=2>UMUM</TH><TH colspan=11>SPESIALIS</TH><TH rowspan=2>PPNS</TH><TH rowspan=2>JUMLAH</TH></TR>
<TR><TH>1</TH><TH>2</TH><TH>3</TH><TH>4</TH><TH>5</TH><TH>6</TH><TH>7</TH><TH>8</TH><TH>9</TH><TH>10</TH><TH>11</TH></TR>”;

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo “<tr><td>”;
echo $row['nomor'];
echo “</td><td>”;
echo $row['jabatan'];
echo “</td><td>”;
echo $row['umum'];
echo “</td><td>”;
echo $row['sp1'];
echo “</td><td>”;
echo $row['sp2'];
echo “</td><td>”;
echo $row['sp3'];
echo “</td><td>”;
echo $row['sp4'];
echo “</td><td>”;
echo $row['sp5'];
echo “</td><td>”;
echo $row['sp6'];
echo “</td><td>”;
echo $row['sp7'];
echo “</td><td>”;
echo $row['sp8'];
echo “</td><td>”;
echo $row['sp9'];
echo “</td><td>”;
echo $row['sp10'];
echo “</td><td>”;
echo $row['sp11'];
echo “</td><td>”;
echo $row['ppns'];
echo “</td><td>”;
echo $row['jumlah'];
echo “</td><td>”;
echo $row['keterangan'];
echo “</td></tr>”;

}
/*
$sum = mysql_query(”SELECT SUM(umum) AS sum_umum,SUM(sp1) AS sum_1,SUM(sp2) AS sum_2,SUM(sp3) AS sum_3,SUM(sp4) AS sum_4,SUM(sp5) AS sum_5,SUM(sp6) AS sum_6,SUM(sp7) AS sum_7,SUM(sp8) AS sum_8,SUM(sp9) AS sum_9,SUM(sp10) AS sum_10,SUM(sp11) AS sum_11,SUM(ppns) AS sum_ppns,SUM(jumlah) AS sum_jumlah FROM dat_k01_detail”);

while($row = mysql_fetch_array( $sum )) {
echo “<tr><td>”;
echo “”;
echo “</td><td>”;
echo “Jumlah”;
echo “</td><td>”;
echo $row['sum_umum'];
echo “</td><td>”;
echo $row['sum_1'];
echo “</td><td>”;
echo $row['sum_2'];
echo “</td><td>”;
echo $row['sum_3'];
echo “</td><td>”;
echo $row['sum_4'];
echo “</td><td>”;
echo $row['sum_5'];
echo “</td><td>”;
echo $row['sum_6'];
echo “</td><td>”;
echo $row['sum_7'];
echo “</td><td>”;
echo $row['sum_8'];
echo “</td><td>”;
echo $row['sum_9'];
echo “</td><td>”;
echo $row['sum_10'];
echo “</td><td>”;
echo $row['sum_11'];
echo “</td><td>”;
echo $row['sum_ppns'];
echo “</td><td>”;
echo $row['sum_jumlah'];
echo “</td><td>”;
echo “”;
echo “</td></tr>”;
}
*/
echo “</table>”;
?>

clip_4.png

php code : generate pdf using mysql and php

April 4, 2007 - 10:09 am No Comments

From http://www.ros.co.nz/pdf/

<?php
// test the table functions
error_reporting(E_ALL);
include(’class.ezpdf.php’);
$pdf =& new Cezpdf(’a4′,’portrait’);
$pdf->selectFont(’./fonts/Helvetica’);
$pdf->ezSetCmMargins(1.5,2,1.5,1.5);

$pdf->addText(370,790,8,”LAMPIRAN I : Keputusan Menteri Tenaga Kerja dan”,0);
$pdf->addText(422,780,8,”Transmigrasi Republik Indonesia”,0);
$pdf->addText(422,770,8,”Nomor : PER.09/MEN/V/2005″,0);
$pdf->addText(422,760,8,”Tanggal : 25-5-2005″,0);
$pdf->line(422,758,555,758);
$pdf->ezSetDy(-50, ‘makeSpace’);

$pdf->ezText(’DATA PEGAWAI PENGAWAS KETENAGAKERJAAN’,10, array(’justification’ => ‘center’));

//————————————————–
// you will have to change these to your settings
$host = ‘172.27.1.28′;
$user = ‘root’;
$password = ’server’;
$database = ‘lp2tk’;
$query = ’select * from dat_k01_detail’;
//————————————————–
// open the connection to the db server
$link = mysql_connect($host,$user,$password);
// change to the right database
mysql_select_db($database);
// initialize the array
$data = array();
// do the SQL query
$result = mysql_query($query);
// step through the result set, populating the array, note that this could also have been written:
// while($data[] = mysql_fetch_assoc($result)) {}
while($data[] = mysql_fetch_array($result, MYSQL_ASSOC)) {}
// make the table

$pdf->ezText(’Triwulan’, 8);
$pdf->ezText(’Tahun’, 8);
$pdf->ezText(’Kab/Kota’, 8);
$pdf->ezText(’Kode’, 8);
$pdf->addText(80,729,8,”:”,0);
$pdf->addText(80,719,8,”:”,0);
$pdf->addText(80,710,8,”:”,0);
$pdf->addText(80,701,8,”: K1″,0);

$pdf->ezSetDy(-10, ‘makeSpace’);
$pdf->ezTable($data,array(’nomor’=>’NO.’, ‘jabatan’=>’JABATAN PENGAWAS KETENAGAKERJAAN’, ‘umum’=>’UMUM’, ’sp1′=>’1′, ’sp2′=>’2′, ’sp3′=>’3′, ’sp4′=>’4′, ’sp5′=>’5′, ’sp6′=>’6′, ’sp7′=>’7′, ’sp8′=>’8′, ’sp9′=>’9′, ’sp10′=>’10′, ’sp11′=>’11′, ‘ppns’=>’PPNS’, ‘jumlah’=>’JUMLAH’, ‘keterangan’=>’KETERANGAN’)
,”, array(’innerLineThickness’ => 1,’outerLineThickness’ => 1.2,’showHeadings’=>1,’shaded’=>1,’showLines’=>1, ‘xPos’=>’center’ ,’xOrientation’=>’center’, ‘width’=>535));
$pdf->ezSetDy(-10, ‘makeSpace’);

$pdf->ezText(’<b>Keterangan Kolom Spesialis</b>
1 = Pesawat Uang Bejana Tekan
2 = Pesawat Angkat Angkut
3 = Pesawat Tenaga dan Produksi
4 = Instalasi Listrik, Lift
5 = Penanggulangan Kebakaran
6 = Konstruksi Bangunan
‘,8, array(’justification’ => ‘left’));

$pdf->addText(200,570,8,”7 = Kesehatan Kerja”,0);
$pdf->addText(200,561,8,”8 = Lingkungan Kerja”,0);
$pdf->addText(200,552,8,”9 = Jamsostek”,0);
$pdf->addText(200,543,8,”10 = Pengupahan dan Waktu Kerja”,0);
$pdf->addText(200,534,8,”11 = Keselamatan Kerja Kimia”,0);

$pdf->addText(395,570,8,”(Wilayah/Daerah, Tanggal, Bulan, Tahun)”,0);
$pdf->addText(375,561,8,”Kepala Instansi atau Kepala Unit Kerja Pengawasan”,0);
$pdf->addText(410,552,8,”Ketenagakerjaan Kabupaten/Kota”,0);
$pdf->addText(435,530,8,”(……………………….)”,0);

//$pdf->ezTable($data,$cols,”, array(’xPos’=>90,’xOrientation’=>’right’,'width’=>300 ,’cols’=>array(’nomor’=>array(’justification’=>’right’),’jabatan’=>array(’width’=>400))));
// do the output, this is my standard testing output code, adding ?d=1
// to the url puts the pdf code to the screen in raw form, good for checking
// for parse errors before you actually try to generate the pdf file.
if (isset($d) && $d){
$pdfcode = $pdf->output(1);
$pdfcode = str_replace(”\n”,”\n<br>”,htmlspecialchars($pdfcode));
echo ‘<html><body>’;
echo trim($pdfcode);
echo ‘</body></html>’;
} else {
$pdf->stream();
$pdf->ezStartPageNumbers(30,50,20,”,”,1);
$pdf->ezStopPageNumbers();
}
ezNewPage()
?>

ros.pdf

clip.png