Jump to content

PHP Checkboxes


Drezard

Recommended Posts

Okay, so I want to create a one of those systems where it pulls records from the database, puts them into a table, then put a checkbox next to each record and at the bottom of the table it has a drop down box with actions like 'Delete selected records' and stuff like that. Any clue on where I could find a tutorial or some code to do this. I know how to do the 'Delete selected records' bit and the display records in a table, but i need help with the checkbox bit and which boxes are checked.

 

Thanks, Daniel

Link to comment
Share on other sites

Well its common question..

 

You do one thing.

Give the  name serially like check1 check2 check3 to each checkbox .... and values for that checkboxes should be the primary key id for.

 

and in post u can loop for check* where *=1,2,3,4etc.. and chek if value is posted or not. if value is posted then u can go for deleting the record.

 

 

Link to comment
Share on other sites

no, you do not do that.

 

You create an array of checkbox values.

<?php
foreach ($records as $record)
{
    echo "<input type=\"checkbox\" value=\"{$record['id']}\" name=\"check[]\"/>\n";
}
?>

Then on the receiving page, you traverse the array:

<?php
foreach ($_POST['check'] as $checkbox)
{
    delete_record($checkbox);
}
?>

after sufficient validation.

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.