大佬教程收集整理的这篇文章主要介绍了php-将Sql数据导出为PDF,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
码:
<?PHP
// Inialize session
session_start();
// check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('LOCATIOn: index.PHP');
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Log in to Intelli-Track</title>
<Meta http-equiv="content-type" content="text/html; charset=utf-8" />
<Meta name="description" content="" />
<Meta name="keywords" content="" />
<link href="1.css" rel="stylesheet" />
<script src="js/jquery-1.8.3.min.js"></script>
<script src="css/5grid/init.js?use=mobile,desktop,1000px"></script>
<script src="js/init.js"></script>
<noscript>
<link rel="stylesheet" href="css/5grid/core.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/tablestyle.css" />
</noscript>
<style type="text/css">
#main {
padding-top: 100px;
padding-left: 55px; }
body
{
line-height: 1.6em;
}
#rounded-corner
{
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
margin: 45px;
width: 480px;
text-align: left;
border-collapse: collapse;
}
#rounded-corner thead th.rounded-company
{
BACkground: #b9c9fe url('table-images/left.png') left -1px no-repeat;
}
#rounded-corner thead th.rounded-q4
{
BACkground: #b9c9fe url('table-images/right.png') right -1px no-repeat;
}
#rounded-corner th
{
padding: 8px;
font-weight: normal;
font-size: 13px;
color: #039;
BACkground: #b9c9fe;
}
#rounded-corner td
{
padding: 8px;
BACkground: #e8edff;
border-top: 1px solid #fff;
color: #669;
}
#rounded-corner tfoot td.rounded-foot-left
{
BACkground: #e8edff url('table-images/botleft.png') left bottom no-repeat;
}
#rounded-corner tfoot td.rounded-foot-right
{
BACkground: #e8edff url('table-images/botright.png') right bottom no-repeat;
}
#rounded-corner tbody tr:hover td
{
BACkground: #d0dafd;
}
</style>
</head>
<body>
<nav id="nav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="landingpage.PHP">Map-Mark</a></li>
<li><a href="logout.PHP">Log-Out</a></li>
<li><a href="credits.html">Credits</a></li>
</ul>
</nav>
<html>
<body>
<?PHP
$hostname = '127.0.0.1:3306';
$dbname = 'mapmark'; // Your database name.
$username = 'root'; // Your database username.
$password = ''; // Your database password. If your database has no password, leave it empty.
MysqL_connect($hostname, $username, $password) or DIE('Connection to host is Failed, perhaps the service is down!');
MysqL_SELEct_db($dbName) or DIE('Database name is not available!');
$query="SELECT * FROM markers";
$result=MysqL_query($query);
$fields_num = MysqL_num_fields($result);
echo "<div id=tab1 style= width:40%;margin-left:auto;margin-right:auto;position:relative;top:200px;>";
echo "<table id=rounded-corner>";//prinTing table headers
echo '
<thead>
<tr>
<th scope="col" class="rounded-company">serial</th>
<th scope="col" class="rounded-q1">Description</th>
<th scope="col" class="rounded-q1">Latitude</th>
<th scope="col" class="rounded-q3">Longitude</th>
</tr>
</thead>';
// prinTing table rows
while($row = MysqL_fetch_row($result))
{
echo "<tr>";
echo "<td>$row[0]</td>";
echo "<td>$row[1]</td>";
echo "<td>$row[2]</td>";
echo "<td>$row[3]</td>";
echo "</tr>\n";
}
echo "</table></div>";
?>
</body>
</html>
本质上看起来是这样的:
我需要的是此页面上的一个按钮,单击该按钮后,同一表格将被下载为PDF文件.
任何帮助,将不胜感激.
解决方法:
易于将html转换为pdf的唯一可行解决方案是使用domPdf库https://code.google.com/p/dompdf/.
您可以使用?pdf get参数添加到同一页面的链接,并在$_GET [‘pdf’]存在时通过dompdf输出PHP代码,而不是将其回显到浏览器.
有关用法,请参见Wiki:
https://code.google.com/p/dompdf/wiki/Usage
我认为在您的情况下,最简单的方法是添加:
如果($_GET [‘pdf’])ob_start();
到页面顶部. (启动输出缓冲区:请参见http://php.net/manual/en/function.ob-start.php
和
if ( $_GET['pdf'] ) {
$html = ob_get_contents(); // this fills $html with all your output generated above.
//do the dompdf stuff here , using the $html variable.
}
以上是大佬教程为你收集整理的php-将Sql数据导出为PDF全部内容,希望文章能够帮你解决php-将Sql数据导出为PDF所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。