|
Posted by Rik on 07/08/06 12:29
David wrote:
> I guess I am missing something here. The input statement here will
> set the value of skill to 16.
Offcourse I can't read the OP's mind, but I'd imagine he has the table
'users', 'skills' & 'userskills', where the table 'userskills' contains the
userid & skillid of the particular skills that person has.
> If I have a lot of boolean items, then
> I can set the fifth bit to "on"--which will indicate Delphi experience
> here--by doing something like:
> (int)applicant = (int)$applicant AND (int($_POST[skill]);
>
> I guess my point is that "checkbox" is either checked or not
> checked. The value passed to skill, in this case, is 16, not a
> boolean value--true or false, for example.
Taking my previous assumption as a starting point, you'd have a form,
containing for instance:
<label for="userid">User-ID</label><input type="text" name="userid"
id="userid" />
<?php
$skills = mysql_query('SELECT id, name FROM skills');
while($skill = mysql_fetch_assoc($result)){
echo '<label for="'.$skill['name'].'">'.$skill['name'].'</label>';
echo '<input type="checkbox" name="skill[]" id="'.$skill['name'].'"
value="'.$skill['id'].'" />';
}
?>
And on submitting you have the very nice compact code:
foreach($_POST['skill'] as $skill){
mysql_query("INSERT INTO userskills (userid, skillid) VALUES
($userid,$skill)");
}
So, this will only add the specific skills checked to the table userskills,
skills the user doesn't have don't need to be added. This way the code is
still valid when adding other skills to the database, without having to
write the code to check for the specific setting. If the form has to be able
to not only assign skills but also to change them, the code will become
somewhat bigger.
Offcourse, one should check post-values and enforce referential integrity,
but that's another story :-).
Grtz,
--
Rik Wasmus
[Back to original message]
|