Forum Moderators: coopster

Message Too Old, No Replies

editing values stored by checkboxes

         

ferhanz

2:01 pm on Jul 29, 2005 (gmt 0)

10+ Year Member



i have the checkboxes in the form like

<table width="100%" border="0">
<tr>
<td bgcolor="#FFFFF2" class="style5"><br>

<span class="style22">6 - Which of the following statements best describing your training abilities </span></td>
</tr>
<tr>
<td bgcolor="#FFFFF2" class="style3">
<input type="checkbox" name="train_ab[]" value="I only take an hour-long session and then half an hour question answers">
I only take an hour-long session and then half an hour question answers<br>
<input type="checkbox" name="train_ab[]" value="I take an hour long session with question-anwers and also provide readingmaterial to the participants">
I take an hour long session with question-anwers and also provide reading material to the participants<br>

<input type="checkbox" name="train_ab[]" value="I conduct a day long session but do not provide handouts">
I conduct a day long session but do not provide handouts<br>
<input type="checkbox" name="train_ab[]" value="I conduct a day long session with varying techniques and provide handouts">
I conduct a day long session with varying techniques and provide handouts<br>
<input type="checkbox" name="train_ab[]" value="I can develop training manuals and other support material for broader dissemination ">
I can develop training manuals and other support material<br>
<input type="checkbox" name="train_ab[]" value="I can conduct training of any length but cannot give out written material">

I can conduct training of any length but cannot give out written material<br>
<input type="checkbox" name="train_ab[]" value="I can conduct training of any length and give out written material">
I can conduct training of any length and give out written material<br>
<input type="checkbox" name="train_ab[]" value=" I am open to accomodate the requirements of the client ">
I am open to accomodate the requirements of the client </td>
</tr>
</table>

now i insert all checkbox values in the db in seperate fields. like if the user selects 3 options in it three records will be inserted into the table, the structure of the table is as follows

Table name [training_ab]
1. training_ab_id...unique id of the table
2. trainer_id ... this acts as a foreign key
3. ability_name ...the values stored from checkboxes

now if i want user to edit this form, wht should i do?
should i first delete all the values first and then insert the new ones (no update query)..if yes then how can i do that

if no then how should i use the update query in it

Thankyou very much

mcibor

7:21 pm on Jul 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your place I would change the checkbox values to numbers.
However this method has it's own appeal. What you can do with your method is create an array of values:

<?php
$abilities = array("I only take an hour-long session and then half an hour question answers", "I take an hour long session with question-anwers and also provide readingmaterial to the participants", "I conduct a day long session but do not provide handouts", ...etc);
$db_abilities = array();//set the type and clear all values
//now get all checked results from db:
$sql = "SELECT DISTINCT ability_name FROM training_ab WHERE trainer_id = '$user_id';
//or SELECT DISTINCT training_ab.ability_name FROM training_ab, user WHERE training_ab.trainer_id = user.user_id AND user.name='$username'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$db_abilities[] = $row["ability_name"];}

//now print out the data:
?>
...
<tr>
<td bgcolor="#FFFFF2" class="style3">
<?php
foreach($abilities as $ability){
?>
<input type="checkbox" name="train_ab[]" value="
<?php echo $ability."\"";
if(in_array($ability, $db_abilities)) echo "checked";
echo ">".$ability;
?><br>
<?php }?>
</td>
</tr>
</table>...


This should check previously checked values
Best regards
Michal Cibor