限制另存为PDF的页面。。PHP
你好 我已经为我的PHP页面启用了分页功能,它工作得很好,即每显示一个页面,从mysql记录3次。但是,当我单击SaveasPDF按钮时,它会显示DB中的所有记录,而不仅仅是3条。事实上,我不知道这样做的逻辑。我尝试了在PHP中用于分页的相同逻辑,但没有成功 代码如下 View.php限制另存为PDF的页面。。PHP,php,mysqli,pdf-generation,Php,Mysqli,Pdf Generation,你好 我已经为我的PHP页面启用了分页功能,它工作得很好,即每显示一个页面,从mysql记录3次。但是,当我单击SaveasPDF按钮时,它会显示DB中的所有记录,而不仅仅是3条。事实上,我不知道这样做的逻辑。我尝试了在PHP中用于分页的相同逻辑,但没有成功 代码如下 View.php <?php error_reporting(E_ALL ^ E_DEPRECATED); ?> <?php //if($_POST['submit']){ if (isset($_POST
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
?>
<?php
//if($_POST['submit']){
if (isset($_POST['submit'])){
require_once 'includes/practice.php';
$pdf->SetFont('times', '', 11);
$pdf->SetFont('aealarabiya', '', 11);
$tb1 = '</br></br>
<table cellspacing="0" cellpadding="5" border="1">
<tr style="background-color:#f7f7f7;color:#333; ">
<td width="60">First Name</td>
<td width="60">Last Name</td>
<td width="80">Employee Number</td>
<td width="80">Department</td>
<td width="60">Email</td>
<td width="80">Total Printers</td>
<td width="80">Total Scanners</td>
<td width="60">Total PCs</td>
<td width="60">Total Phones</td>
<td width="60">Other Equipments</td>
</tr>
</table>';
include('connect.php');
$result1= $link->query("SELECT * FROM employees");
while($row = mysqli_fetch_array($result1,MYSQLI_ASSOC)){
$tb2 = '<table cellspacing="0" cellpadding="5" border="1">
<tr>
<td width="60">'.$row['first_name']. '</td>
<td width="60">'.$row['last_name'] . '</td>
<td width="80">'.$row['emp_number'] .'</td>
<td width="80">'.$row['department'].'</td>
<td width="60">'.$row['email'].'</td>
<td width="80">'.$row['total_printers'].'</td>
<td width="80">'.$row['total_scanners'].'</td>
<td width="60">'.$row['total_pc'].'</td>
<td width="60">'.$row['total_phones'].'</td>
<td width="60">'.$row['other_equips'].'</td>
</tr>
</table>';
$tb1 = $tb1.$tb2;
}
$pdf->writeHTML($tb1, true, false, false, false, '');
ob_end_clean();
$pdf->Output('Report.pdf', 'D');
}
?>
将所有评论放在一起:
<?php
/**** display-all-employees.php ***/
error_reporting(E_ALL);
ini_set('display_errors', 1);
// connect to the database
// number of results to show per page
$per_page = 3;
// figure out the total pages in the database
$result = $mysqli->query("SELECT * FROM employees ORDER BY emp_id"))
if ($result->num_rows != 0)
{
/* calculate and display pagination */
/** do stuff here to set $i **/
echo "<a href='view-page.php?page=$i'>$i</a> ";
}
else
{
echo "No results to display!";
} /* end query */
/**** jump to another page : display-all-employees.php -> view-page.php ***/
/********** view-page.php **********/
// connect to the database
// number of results to show per page
$rec_limit = 3;
$start = $_GET['page'];
/* check values here */
echo"[ $start / $rec_limit ]";
$result = $link->query("SELECT * FROM employees LIMIT $start, $rec_limit");
/* do stuff here */
echo "<a href='print-the-results-of-this-page-as-pdf.php?page=$start'>Print PDF with reulsts of this page #$start</a> ";
/**** jump to another page : view-page.php -> print-the-results-of-this-page-as-pdf.php ***/
/**** print-the-results-of-this-page-as-pdf.php ***/
error_reporting(E_ALL);
ini_set('display_errors', 1);
// connect to the database
$rec_limit = 3;
$start = $_GET['page'];
/* check value here */
echo"[ $start ]";
$result = $link->query("SELECT * FROM employees LIMIT $start, $rec_limit");
/* do stuff here with your PDF -> $pdf->Output('Report.pdf', 'D'); */
?>
您的问题不清楚,除非您的意思是PDF生成只需要显示分页显示的3条记录。如果是这种情况,您需要修改select以将查询限制为分页中的值。不清楚:用户可以使用分页将页面上显示的3个结果导出为PDF?如果是,如上所述,$result1=$link->query(“从员工中选择*);->需要一个限额1美元,3美元;您需要将变量从一页传递到另一页,再传递到query@OldPadawan它将如何工作。。。我已经在PHP页面中进行分页,但在pdf中没有得到结果though@OldPadawan更新了我的问题,并提到我是如何在PHP页面中应用分页的。。。这是我申请的pdf,但没有工作…你显示页面=1:意味着你想显示记录1;2.3.第2页->显示4,5,6。要实现这一点,您需要在SQL查询中设置一个限制。您有$start和$end,使用它们来限制您的查询,例如SELECT*FROM EMPLOYEE LIMIT 0,3或SELECT*FROM EMPLOYES LIMIT where_OU_to_start,limited_number_记录。生成PDF的页面需要为查询获取一些vars$start和$end
<?php
// connect to the database
//include('connect-db.php');
$mysqli = new mysqli("localhost", "root", "", "mydb");
// number of results to show per page
$per_page = 3;
// figure out the total pages in the database
if ($result = $mysqli->query("SELECT * FROM employees ORDER BY emp_id"))
{
if ($result->num_rows != 0)
{
$total_results = $result->num_rows;
// ceil() returns the next highest integer value by rounding up value if necessary
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
echo "<p><a href='view.php'>View All</a> | <b>View Page:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
if (isset($_GET['page']) && $_GET['page'] == $i)
{
echo $i . " ";
}
else
{
echo "<a href='view-pagin.php?page=$i'>$i</a> ";
}
}
echo "</p>";
// display data in table
echo "<table border='1' cellpadding='10'>";
echo "<tr><th>First Name</th> <th>Last Name</th><th>Employee Number</th><th>Department</th><th>Email</th><th>Total Printers</th><th>Total Scanners</th><th>Total PCs</th><th>Total Telephones</th><th>Other Equipments</th></tr>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// find specific row
$result->data_seek($i);
$row = $result->fetch_row();
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row[1] . '</td>';
echo '<td>' . $row[2] . '</td>';
echo '<td>' . $row[3] . '</td>';
echo '<td>' . $row[4] . '</td>';
echo '<td>' . $row[5] . '</td>';
echo '<td>' . $row[6] . '</td>';
echo '<td>' . $row[7] . '</td>';
echo '<td>' . $row[8] . '</td>';
echo '<td>' . $row[9] . '</td>';
echo '<td>' . $row[10]. '</td>';
echo '<td class="forscreen"><a href="view-one.php?emp_id=' . $row[0] . '">View</a></td>';
echo '<td class="forscreen"><a href="edit.php?emp_id=' . $row[0] . '">Edit</a></td>';
echo '<td class="forscreen"><a href="delete.php?emp_id=' . $row[0] . '">Delete</a></td>';
echo '<td class="forscreen"><a href="view-aceessory.php?emp_number='.$row[3].'">View Accessories</a></td>';
//echo '<td class="forscreen"><a href="equipments.php?emp_number=' .$row[3].'">Add Accessories</a></td>';
echo '<td class="forscreen"><a href="equipments.php?emp_number=' .$row[3] .'&first_name='.$row[1] . '">Add Accessories</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
}
else
{
echo "No results to display!";
}
}
// error with the query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
?>
<?php
//if($_POST['submit']){
if (isset($_POST['submit'])){
require_once 'includes/practice.php';
$pdf->SetFont('times', '', 11);
$pdf->SetFont('aealarabiya', '', 11);
//require_once 'includes/practice.php';
//$pdf->SetFont('times', '', 11);
// number of results to show per page
$rec_limit = 3;
if( isset($_GET{'page'} ) ) {
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}else {
$page = 0;
$offset = 0;
}
//$abpage=$this->Cell(0, 3, "Page " . $this->PageNo() . "/{nb}", 0, 0, "C");
$tb1 = '</br></br>
<table cellspacing="0" cellpadding="5" border="1">
<tr style="background-color:#f7f7f7;color:#333; ">
<td width="80">Full Name</td>
<td width="80">Employee Number</td>
<td width="80">Department</td>
<td width="60">Email</td>
<td width="70">Total Printers</td>
<td width="70">Total Scanners</td>
<td width="60">Total PCs</td>
<td width="60">Total Phones</td>
<td width="60">Other Equipments</td>
</tr>
</table>';
//include('connect-db.php');
//$start=1;
include('connect.php');
$my_value=$_POST['my_value_of_page'];
$result = $link->query("SELECT * FROM employees LIMIT $my_value, 3");
//$result1= mysql_query("SELECT * FROM employees LIMIT $per_page");
// while($row = mysql_fetch_assoc($result1)){
while($row =mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$tb2 = '<table cellspacing="0" cellpadding="5" border="1">
<tr>
<td width="80">'.$row['first_name'] . ' '.$row['last_name'].'</td>
<td width="80">'.$row['emp_number'] .'</td>
<td width="80">'.$row['department'].'</td>
<td width="60">'.$row['email'].'</td>
<td width="70">'.$row['total_printers'].'</td>
<td width="70">'.$row['total_scanners'].'</td>
<td width="60">'.$row['total_pc'].'</td>
<td width="60">'.$row['total_phones'].'</td>
<td width="60">'.$row['other_equips'].'</td>
</tr>
</table>';
$tb1 = $tb1.$tb2;
}
$pdf->writeHTML($tb1, true, false, false, false, '');
ob_end_clean();
$pdf->Output('Report.pdf', 'D');
}
?>
<?php
/**** display-all-employees.php ***/
error_reporting(E_ALL);
ini_set('display_errors', 1);
// connect to the database
// number of results to show per page
$per_page = 3;
// figure out the total pages in the database
$result = $mysqli->query("SELECT * FROM employees ORDER BY emp_id"))
if ($result->num_rows != 0)
{
/* calculate and display pagination */
/** do stuff here to set $i **/
echo "<a href='view-page.php?page=$i'>$i</a> ";
}
else
{
echo "No results to display!";
} /* end query */
/**** jump to another page : display-all-employees.php -> view-page.php ***/
/********** view-page.php **********/
// connect to the database
// number of results to show per page
$rec_limit = 3;
$start = $_GET['page'];
/* check values here */
echo"[ $start / $rec_limit ]";
$result = $link->query("SELECT * FROM employees LIMIT $start, $rec_limit");
/* do stuff here */
echo "<a href='print-the-results-of-this-page-as-pdf.php?page=$start'>Print PDF with reulsts of this page #$start</a> ";
/**** jump to another page : view-page.php -> print-the-results-of-this-page-as-pdf.php ***/
/**** print-the-results-of-this-page-as-pdf.php ***/
error_reporting(E_ALL);
ini_set('display_errors', 1);
// connect to the database
$rec_limit = 3;
$start = $_GET['page'];
/* check value here */
echo"[ $start ]";
$result = $link->query("SELECT * FROM employees LIMIT $start, $rec_limit");
/* do stuff here with your PDF -> $pdf->Output('Report.pdf', 'D'); */
?>