dtkjthe4025 2018-10-16 03:21 采纳率: 0%
浏览 218

如何在分页中保持单选按钮的选中值?

How will I make stay and hold the value of the checked radio button when I go to the next page? should I use session method? Here's my code:

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();
}
  • 写回答

2条回答 默认 最新

  • drn34916 2018-10-16 03:50
    关注
    • You could use $_SESSION["values"] = "SOMETHING";
    • Another method could be <input type="checkbox" name="pagination" value="SOMETHING" hidden> inside a form
    • And the last and most insecure resourse is sending info through URL like this <a href="nexturl.php?values=SOMETHING" and in the page that you want to get the info, you have to use $_GET['values']
    • after that, you can use inside the checkbox <input type="checkbox" name="whaTever" value="SOMEVALUE" checked>
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀