PHP Loop / Edit Checkbox problem

Hi Chaps,

Outline:
I have a table of Jobs and a table of Tasks. The Tasks are linked to the Jobs via FOREIGN KEY and is working fine.
There can be say 10 Tasks linked to a Job, in this example, there are 4 already linked.
I have a Query that selects the FK_task_id field from a table:
rsJob:

SELECT FK_task_id FROM tbl_job LEFT OUTER JOIN tbl_task_item ON tbl_task_item.FK_job_id=tbl_job.job_id;

Producing:

FK_task_id
1
2
4
10

The second Query lists all the Tasks:
rsTask:

SELECT task_id, task_title FROM tbl_task;

Producing:

task_id task_title
1 Prep
2 Trans
3 Proof
4 TypeF
5 TypeR
6 Corr
7 FCheck
8 FCorr
9 Mem
10 Ship

What I’m trying to do is that lists the total 10 Tasks, and check the checkboxes that are already linked.
The PHP code I have at the moment:

<?php do { ?>
       <?php echo $row_rsTask['task_title']; ?> - <input type="checkbox" name="task[<?php echo $row_rsTask['task_id']; ?>]" value="<?php echo $row_rsTask['task_id']; ?>"  <?php if (!(strcmp(htmlentities($row_rsJob['FK_task_id'], ENT_COMPAT, 'utf-8'),htmlentities($row_rsTask['task_id'], ENT_COMPAT, 'utf-8')))) {echo "checked=\\"checked\\"";} ?> /></br>
        <?php } while ($row_rsTask = mysql_fetch_assoc($rsTask)); ?>

The problem is that only the first record from rsJob is checked (1 - Prep), where 1 - Prep, 2 - Trans, 4 - TypeF and 10 - Ship should all be ticked.
Has anyone got any ideas on how to display all 10 Tasks and also get all 4 checkboxes to check in this Loop?

why can’t you use while loop instead of do…while?

Hi,

how do you initialize $row_rsJob ?