我希望在多个页面中显示大量数据,其中每个页面包含20个数据。我在使用表格后给出一些价值后搜索数据。但是在显示数据期间,post值适用于第一页。从第2页开始,帖子值不起作用。以下是我的行动代码页..
<?php
$conn = mysql_connect("localhost","root","1amShaw0n");
mysql_select_db("bkash_plus",$conn);
$account_no = $_POST['account_no'];
$remarks = $_POST['remarks'];
$open_by= $_SESSION['user_name'];
$result = mysql_query("SELECT count(*) as count FROM tickets where created_by='$open_by' and status='Closed' and account_no like '%$account_no%' and remarks like '%$remarks%'");
if(false === $result) {
throw new Exception('Query failed with: ' . mysqli_error());
} else {
while ($row = mysql_fetch_assoc($result)) {
$row_count= $row['count'];
}
}
$page_count = 0;
if (0 === $row_count) {
// maybe show some error since there is nothing in your table
} else {
// determine page_count
$items_per_page = 20;
$page_count = (int)ceil($row_count / $items_per_page);
$page = 1;
if($page > $page_count) {
// error to user, maybe set page to 1
$page = 1;
}
}
// make your LIMIT query here as shown above
// determine page number from $_GET
$page = 1;
if(!empty($_GET['page'])) {
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
if(false === $page) {
$page = 1;
}
}
// set the number of items to display per page
$items_per_page = 20;
// build query
$offset = ($page - 1) * $items_per_page;
// Collects data from "friends" table
$data = mysql_query("SELECT * FROM bkash_plus.tickets where created_by='$open_by' and status='Closed' and account_no like '%$account_no%' and remarks like '%$remarks%' order by tickets_id desc LIMIT " . $offset . "," . $items_per_page)
or die(mysql_error());
// $result = mysql_query($data) or die ("Error in query: $data. ".mysql_error());
// puts the "friends" info into the $info array
//$info = mysql_fetch_array( $data );
if (mysql_num_rows($data) >= 0) {
echo '<table border="2" width="1030px">
<tr>
<th><center><font color="blue">Ticket_ID</font><center></th>
<th><center><font color="blue">Account No</font><center></th>
<th><center><font color="blue">Created Time</font><center></th>
<th><center><font color="blue">Service Type</font><center></th>
<th><center><font color="blue">Category</font><center></th>
<th><center><font color="blue">Sub_Category</font><center></th>
<th><center><font color="blue">Status</font><center></th>
<th><center><font color="blue">Remarks</font><center></th>
<th><center><font color="blue">Created By</font><center></th>
</tr>';
while($info = mysql_fetch_array($data)){
echo '
<tr>
<td><center><a href=ticket_view_data_front.php?tickets_id='.$info['tickets_id'].'>'.$info['tickets_id'].'</a><center></td>
<td><center>'.$info['account_no'].'<center></td>
<td><center>'.$info['created_time'].'<center></td>
<td><center>'.$info['service_type'].'<center></td>
<td><center>'.$info['category'].'<center></td>
<td><center>'.$info['sub_category'].'<center></td>
<td><center>'.$info['status'].'<center></td>
<td><center>'.$info['remarks'].'<center></td>
<td><center>'.$info['created_by'].'<center></td>
</tr>';
}
echo '</table>';
}
// later when outputting page, you can simply work with $page and $page_count to output links
// for example
for ($i = 1; $i <= $page_count; $i++) {
if ($i === $page) { // this is current page
echo 'Page ' . $i . '';
} else { // show link to other page
echo '>>';
echo '<a href="view_all_ticket_front_closed_search_result.php?page=' . $i . '">Page ' . $i . ' </a>';
}
}
?>
这里&#34; view_all_ticket_front_closed_search_result.php&#34;是行动页面..
对于第一页,我得到了前20行的结果,但在第2页我得到了以下错误...
Notice: Undefined index: account_no in C:\xampp\htdocs\bkash_plus\view_all_ticket_front_closed_search_result.php on line 74
Notice: Undefined index: remarks in C:\xampp\htdocs\bkash_plus\view_all_ticket_front_closed_search_result.php on line 75
以下是传递POST值的表单页面。
<form method="post" class="form-horizontal" role="form">
<!-- Account No: <input type="text" name="account_no">
ID: <input type="text" name="id">
<input type="submit" name="submit" value="Check"> -->
<div class="form-group">
<label class="control-label col-sm-2" for="account_no">Account ID:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="account_no" name="account_no" style="height:35px;width:160px">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="remarks">Remarks:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="remarks" name="remarks" style="height:35px;width:160px">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10 ticket">
<input type="submit" class="btn" name="submit" value="View" formaction="view_all_ticket_front_closed_search_result.php">
</div>
</div>
</form>
任何人都可以帮我解决这个问题。