|
|
|
mPDF เชื่อมต่อฐานข้อมูลได้ไหมคะ อยากแปลงphp and mySQL code to PDF น่ะค่ะ ช่วยดูโค๊ดให้ทีค่ะ ไม่เข้าใจเจงๆ |
|
|
|
|
|
|
|
Code (PHP)
<?php
@session_start();
include("mpdf.php");
$user_id = $_SESSION[user_id];
$role = $_SESSION[role];
$company_id = $_SESSION[company_id];
$user_level = $_SESSION[user_level];
if($user_id==NULL){
//echo "<meta http-equiv='refresh' content='0;URL=login.php'>";
header('location: login.php');
exit();
}
//print_r($result);
//------------------- refer -----------------
/* $start_date = $_GET["start_date"];
$end_date = $_GET["end_date"];
$factor = $_GET["factor"];
$status = $_GET["status"];
$str_search = $_GET["str_search"];
$company = $_GET["company"];
$type_action = str_replace("%20", " ", $_GET["type_action"]);
$sel_root = $_GET["sel_root"];
$sel_cause = $_GET["sel_cause"]; */
$start_date = $_POST["hide_date_start"];
$end_date = $_POST["hide_date_end"];
$company = $_POST["hide_company"];
$factor = $_POST["hide_factor"];
//$person =$_POST["hide_staff"];
// $staff=@join(",",$person);
//echo $person;
$status = $_POST["hide_status"];
$str_search = $_POST["hide_str_search"];
$type_action = str_replace("%20", " ", $_POST["hide_type_action"]);
$sel_cause = $_POST["hide_sel_root"];
//echo $sel_root;
$staff = $_POST["hide_sel_staff"];
?>
<?php
$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true; // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Acme Trading Co. - Invoice");
$mpdf->SetAuthor("Acme Trading Co.");
$mpdf->SetWatermarkText("ITA Report");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
// $test_txt="PHP SHOW!!!";
//---Connect DB ---//
$host="n6-mysql5-3.smartyhost.com.au";
$username="whereol";
$password="terrace18";
$db="whereol_db";
$Conn = mysql_connect( $host,$username,$password) or die ("Error Connect to Database");
mysql_query("SET NAMES utf8",$Conn);
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
mysql_query("SET NAMES UTF8");
$sql = "SELECT * FROM company WHERE company_id='".$company_id."'";
$result = mysql_query($sql);
$show = mysql_fetch_array($result);
$sql_city = "SELECT * FROM city WHERE city_id='".$show[city]."'";
$result_city = mysql_query($sql_city);
$show_city = mysql_fetch_array($result_city);
$sql_state = "SELECT * FROM state WHERE state_id='".$show[state]."'";
$result_state = mysql_query($sql_state);
$show_state = mysql_fetch_array($result_state);
//---///
//$address=$show[address];
$html = '
<html>
<head>
<style>
body {font-family: sans-serif;
font-size: 10pt;
}
p { margin: 0pt;
}
td { vertical-align: top; }
.items td {
border-left: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
table thead td { background-color: #EEEEEE;
text-align: center;
border: 0.1mm solid #000000;
}
.items td.blanktotal {
background-color: #FFFFFF;
border: 0mm none #000000;
border-top: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
.items td.totals {
text-align: right;
border: 0.1mm solid #000000;
}
</style>
</head>
<body>
<!--mpdf
<htmlpageheader name="myheader">
<br/><table width="100%"><tr>
<td width="50%" style="color:#0000BB;"><span style="font-weight: bold; font-size: 14pt;">Acme Trading Co.</span><br />123 Anystreet<br />Your City<br />GD12 4LP<br /><span style="font-size: 15pt;">☎</span> 01777 123 567</td>
<td width="50%" style="text-align: right;">Invoice No.<br /><span style="font-weight: bold; font-size: 12pt;">0012345</span></td>
</tr></table>
</htmlpageheader>
<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
Page {PAGENO} of {nb}
</div>
</htmlpagefooter>
<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->
<div style="text-align: right">Date: '.date('jS F Y').'</div>
<table width="100%" style="font-family: serif;" cellpadding="10">
<tr>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="color:#0000BB;"><span style="font-weight: bold; font-size: 14pt;">'.$show[company_name].'</span><br />
'.$show[address].'><br />
'.$show_city[city].'><br />
'.$show_state[state].' '.$show[post_code].'<br />
<span style="font-size: 15pt;">☎</span>'.$show[phone].'</span></td>
<td width="10%"> </td>
<td width="45%" style="border: 0.1mm solid #888888;">
<table align="right" width="70%" border="0" style="font-size: 10pt;">
<tr>
<td width="41%" style="text-align: right">Date:</td>
<td width="59%"> </td>
</tr>
<tr>
<td style="text-align: right">Motivating Factor:</td>
<td> </td>
</tr>
<tr>
<td style="text-align: right">Type of Action:</td>
<td> </td>
</tr>
<tr>
<td style="text-align: right">Status:</td>
<td> </td>
</tr>
<tr>
<td style="text-align: right">Word Filte:</td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
<table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
<thead>
<tr>
<td width="15%">REF. NO.</td>
<td width="10%">QUANTITY</td>
<td width="45%">DESCRIPTION</td>
<td width="15%">UNIT PRICE</td>
<td width="15%">AMOUNT</td>
</tr>
</thead>
<tbody>
<!-- ITEMS HERE -->
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<tr>
<td align="center">MF1234567</td>
<td align="center">10</td>
<td>Large pack Hoover bags</td>
<td align="right">£2.56</td>
<td align="right">£25.60</td>
</tr>
<tr>
<td align="center">MX37801982</td>
<td align="center">1</td>
<td>Womans waterproof jacket<br />Options - Red and charcoal.</td>
<td align="right">£112.56</td>
<td align="right">£112.56</td>
</tr>
<tr>
<td align="center">MR7009298</td>
<td align="center">25</td>
<td>Steel nails; oval head; 30mm x 3mm. Packs of 1000.</td>
<td align="right">£12.26</td>
<td align="right">£325.60</td>
</tr>
<!-- END ITEMS HERE -->
<tr>
<td class="blanktotal" colspan="3" rowspan="6"></td>
<td class="totals">Subtotal:</td>
<td class="totals">£1825.60</td>
</tr>
<tr>
<td class="totals">Tax:</td>
<td class="totals">£18.25</td>
</tr>
<tr>
<td class="totals">Shipping:</td>
<td class="totals">£42.56</td>
</tr>
<tr>
<td class="totals"><b>TOTAL:</b></td>
<td class="totals"><b>£1882.56</b></td>
</tr>
<tr>
<td class="totals">Deposit:</td>
<td class="totals">£100.00</td>
</tr>
<tr>
<td class="totals"><b>Balance due:</b></td>
<td class="totals"><b>£1782.56</b></td>
</tr>
</tbody>
</table>
<div style="text-align: center; font-style: italic;">Payment terms: payment due in 30 days</div>
</body>
</html>
';
$mpdf->WriteHTML($html);
$mpdf->Output(); exit;
exit;
?>
Tag : PHP, MySQL, Report Others
|
|
|
|
|
|
Date :
2012-05-23 18:58:37 |
By :
oneplus048 |
View :
2164 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|