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.