dongmin1166 2014-01-07 14:37
浏览 129

PHP - 多个粘性复选框

there is a need to read different jobs (e.g., job1, job2, job3, ... job n) from a database and place them on a form for a user to select those jobs a user likes through checkbox Selection as Shown below.

  • ( ) Job 1 description1,
  • (X) Job 2 description2
  • (X) Job 3 description3
  • :
  • :
  • ( ) Job N descriptionN

Given that the number of jobs can be too high for a single page to display, pagination is employed so that the whole form is broken into number of pages. the requirement is that a users's checknbox Selection on a given page has to be sticky even when a user navigates through different pages of this form. how to achieve this.

if JQuery can be of use to Simplify the task, please Show me As well.

I use the following code:

 function selected($job_id)
 {          
    if (empty($_POST['job_selection'])) || (!is_array($_POST['job_selection'])) ||       (!in_array($job, $_POST['job_selection'])) {
      return '1';
    }

    return 'checked';
  }    


     $q10 = "SELECT ...
 $r10 = mysqli_query ($dbc, $q10);                                    
     if (mysqli_num_rows($r10) > 0) {

      while ($row10 = mysqli_fetch_array($r10, MYSQLI_ASSOC)) 
      {

       if (isset($_POST['job_selection'])){   
        $jid = $row10['job_id'];
            echo '<td align="left"><p class="normal_text"><input type="checkbox" name="job_selection[]" value="' . $row10['job_id'] . '" selected($jid) />' . $row10['job_name'] . '</p></td>';      
        } 
        else 
        {             
           echo '<td align="left"><p class="normal_text"><input type="checkbox" name="job_selection[]" value="' . $row10['job_id'] . '" />' . $row10['job_name'] . '</p></td>';               
        }
     } 
   }

The Issue is that when Navigating through pages by clicking the page number, the form is not necessarily Submitted - hence, $_POST['job_selection'] will be empty.

  • 写回答

1条回答 默认 最新

  • doq8211 2014-01-07 14:54
    关注

    You can use client-side pagination for your list.

    There is a lot of simple jQuery plugins to achieve it : http://www.smashingapps.com/2013/05/06/16-beautiful-jquery-pagination-plugins.html

    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据