Jump to content

dynamically create,store and retrieve values from multiple checkboxes


aliasnikhil

Recommended Posts

hey i am using a MySql database and i need to create a dynamic HTML table with one of its columns as checkboxes.so i have to create multiple checkboxes.but these checkbox values are to be stored in a mysql table and then later retrieved when form reloads.and depending on previous state when form was submitted, the newly created checkboxes have to be checked in the same manner.so how do i store multiple checkbox values in my table and also how do i retrieve them?

please help.

Link to comment
Share on other sites

I am not sure you really need to do this. You are going to write code to process the forms so why not write code to generate them? Both generating and processing the forms may need to use the same logic.

 

I think you need to think out the forms you will need. How many check boxes in the first form and how many variations of the second form will that generate. Could you use other methods to clarify the info from the first form such as drop downs?

 

Why not post and general idea of what is needed?

Link to comment
Share on other sites

yes exactly both processing and generating the form will require the same logic.lets take an example:i have to create an html table with 10 rows,each row having a column of checkbox.now if the user had checked some of the checkboxes in previous login,then the newly created form should 'check' them as the form loads.so this means it should first access the mysql database and then corresponding to the username it should find which checkboxes were ticked last time.so the help i need is previously storing the 'checked' data in mysql and then later retrieving them to display the form as i described above.i hope this information is sufficient.sorry i was short on info last time.

Thanks for your reply.

Link to comment
Share on other sites

To do this simple we will need one table to store the checkbox results for each user.

The DB will have a column for the user id number and ten other columns for the box results.

Add the row with a new user when they register and set the all the box results to 0. That's zero (the number).

 

Hard code the table:

 

<table width="400" border="1" id="pick_table">
<caption>Your Pick</caption>
<tr>
	<th>Pick</th>
	<th>Main Title</th>
	<th>Sub Title</th>
</tr>
<tr>
	<td><input type="checkbox" id="option1" value="row1" <?php if($box[1] == 1){echo "checked=\"checked\"";} ?>></td>
	<td>Sword of Red Witch</td>
	<td>Not so powerful, but fast</td>
</tr>
<tr>
	<td><input type="checkbox" id="option2" value="row2" <?php if($box[2] == 1){echo "checked=\"checked\"";} ?>></td>
	<td> </td>
	<td> </td>
</tr>
</table>

 

When you query the checkbox DB the returned array is called $box[].

 

This table needs a submit button and you need to update the checkbox DB when it's clicked.

 

P.S. You can put the descriptions into a new DB table and run the coding for this table as a loop if you work at it.

 

Use this to check how the boxes get check:

 

<?php
$box[1] = 0;
$box[2] = 1;
?>

Link to comment
Share on other sites

sunfighter i am very thankful to you,you understood my need exactly.i just need you to be more elaborate.

10 items as i said was just an example.actually i need 30 to 40 checkboxes per user.so is it feasible to have so many columns?what i thought was that i could just keep one column for the checkbox and store the key of the option corresponding to which checkboxes were ticked.and in case for updating,i will delete all rows corresponding to the user id and write new rows along with all the checkboxes ticked (although this might increase processing load and probably time).help me with this dilemma!!!

 

and can you also tell me how do i retrieve from the DB, the checkboxes ticked and how to insert in a PHP array $box[].

 

thank you for helping me out  :D

Link to comment
Share on other sites

aliasnikhil I will help you. BUT I need a few questions answered.

 

Is it possible that a user would have all 40 checkboxes checked?

 

Can we group some of the checks together?

 

And why so many???

 

Is this a game thing?

 

Does everything need to be shown at once?

 

I would like a list of what is in your table looks like. Put every thing that appears in a row <tr> on a single line so I can see the number of <td>'s I need.

Don't put it here PM me with it. and explain it for me and I'll see if I can code it for you. Please make the list out in English if it is going to be on a foreign language web site.

 

Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.