[eluser]Samuurai[/eluser]
Hi everyone,
I'm trying to get my head around using set_checkbox to populate a form from the database if, for example, a user wants to edit their settings.
Say I have three tables User, Skills and User_Skills. User is a normal user table, Skills has a skill id and the name of the skill and the User_Skills table has two fields, user_id and skill_id.
In my controller, I first get the skills so my view can generate the checkboxes using:
Code:
SELECT name FROM Skills
I then get the user details
Code:
SELECT * FROM User WHERE id = $id
My view then has this line:
Code:
<input type="checkbox" class="checkbox" name="skills[]" value="<?=$skills[$i]['id']?>" <?=set_checkbox('skills[]',$skills[$i]['id'],WHAT_DO_I_PUT_HERE)?> />
I thought about doing a third query on user_skills and then doing an in_array() function to get a true/false output... but seriously...three queries?
I also thought I could do a GROUP_CONCAT in my User query and return the skill ID's comma seperated and then doing a strstr() but that could be prone to error.
How else can I do this?