You are here: Re: checkbox - again « All PHP « IT news, forums, messages
Re: checkbox - again

Posted by David on 10/10/92 11:52

On Sat, 8 Jul 2006 14:29:48 +0200, "Rik" <luiheidsgoeroe@hotmail.com>
wrote:

>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'].'" />';
>}
>?>

Ok. I can accept this :-); however, the original post does not show
anything like this. He is passing a constant in his checkbox--the
number 16.

>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)");
>}

We do agree, it seems, that his "problem" was a syntax in his query
statement, I think.

>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.


If you wanted to maintain a record of all languages that a person is
proficient in, isn't a multiple select perhaps a better way to do
this? Using a checkbox simply does not make sense to me.

>Offcourse, one should check post-values and enforce referential integrity,
>but that's another story :-).

Sure, ruin a nice conversation talking about work :-)

>Grtz,

David

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация