kool_samule Posted June 7, 2010 Share Posted June 7, 2010 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 https://forums.phpfreaks.com/topic/204099-php-loop-edit-checkbox-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.