Jump to content

multiple check boxes


kenny22

Recommended Posts

Yes, of course. You would have to elaborate on "...post the values into different rows of DB" for us to provide any worthwhile advice.

 

But, let's say, for example, that you want a page where you can "deactivate" records. So you would generate a page with a single check box for each record next to a tile for each record or some way for the user to identify which record is which. Now, you can decide to only include currently active records or include all record and check/uncheck each record according to it's current active status.

 

For simplicity I will assume this will only include currently active records with the options to deactivate them. I have left of some necessary code - such as connecting to the db, validation/data cleansing, etc.

 

Page to create form

<?php
//Run query to get list of currently active records
$query = "SELECT * FROM table WHERE active = 1";
$result = mysql_query($query);
//Create HTML form code to display checkboxes for each active record
$formFields = '';
while($row = mysql_fetch_assoc($result))
{
    $formFields .= "<input type=\"{$row['id']}\" name=\"recID[]\" />{$row['name']}<br />\n";
}

?>
<html>
<body>

<form action="deactivate.php">
  Select the records to deactivate:<br />
  <?php echo $formFields; ?>
  <button type="submit">Deactive Selected</button<
</form>

</body>
</html>

 

Page to process the form

//Create id list from submitted values for query
$idList = implode(', ', $_POST['ids']);

//Create and run query to update records
$query = "UPDATE table SET active = 0 WHERE id IN ({$idList})";
$result = mysql_query($query);

Link to comment
Share on other sites

Thanks for reply

 

more info for you, the form pulls in a list of names from database and has a check box for each name, i want to be able to select 11 names by checking the boxes next to the names and submit the form so it enters the value '1'  into a field for each name

 

example:

 

name1, 1 (check box  selected)

name2, 1 (check box  selected)

name3, 0 (check box not selected)

 

kenny

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.