Jump to content

PHP Loop / Edit Checkbox problem


kool_samule

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.