【发布时间】:2018-10-16 14:40:33
【问题描述】:
当我转到下一页时,如何保持选中的单选按钮的值?我应该使用会话方法吗?这是我的代码:
include('includes/dbconn2.php');
// PAGINATION
if(isset($_GET['pageno'])){
$pageno = $_GET['pageno'];
}else{
$pageno =1;
}
$no_of_records_per_page = 5;
$offset = ($pageno-1) * $no_of_records_per_page;
// get no of total no. pages
$total_pages_sql = "SELECT COUNT(item_id) AS total FROM items WHERE cat_id = 4";
$result = $conn->query($total_pages_sql);
$total_rows = $result->fetch_assoc();
// calculate total pages with results
$total_pages = ceil($total_rows['total'] / $no_of_records_per_page);
// sql query for pagination
$get_items = "SELECT item_id, item_name FROM items WHERE cat_id = 4 LIMIT $offset, $no_of_records_per_page";
if($results=$conn->query($get_items)){
while($row=$results->fetch_assoc()){
$app_id=$row['item_id'];
$app_name=$row['item_name'];
?>
<tr>
<td><?php echo $app_name; ?> </td>
<td> <label class="container"><input type="radio" name="<?php echo $app_name?>-<?php echo $app_id; ?>" value="P0"><span class="checkmark"></span></label> </td>
<td> <label class="container"><input type="radio" name="<?php echo $app_name?>-<?php echo $app_id; ?>" value="P1"> <span class="checkmark"></span></label></td>
<td> <label class="container"><input type="radio" name="<?php echo $app_name?>-<?php echo $app_id; ?>" value="P2"> <span class="checkmark"></span></label></td>
</tr>
<?php
}
$results->close();
}
【问题讨论】:
-
您可能需要考虑使用 ajax 进行分页。它将为您简化流程,并从客户的角度看起来更好。
标签: php mysql pagination