Hello everybody...!!!
i have a table and having different fields, now i want to put checkbox on every row which is used for to delete or update the specific record. when select any row from the record the delete or update button or link should work properly. so plz help me in this php code if any body knows.

With Best Regards.
Thnx to all in advance.

6 Years
Discussion Span
Last Post by freddavis

I'm not going to give you the code directly but I'll tell you how to do it.

1. Assign an ID to each of the row elements. This should be fine if you already have a primary key in your table.

2. Normally you would be looping through each of the rows to display it on your page. In this loop, create a new column where the text boxes will be stored. Use the following code for the check boxes

<input type='checkbox' name='users[]' value='{$row['primary_id']}'

The users variable will store an array of all the checkboxes which have been selected.

3. You can enable/disable a button at the bottom of the page for either updating or deleting a specific record through javascript.

4. To delete: Loop through the users variable and delete the rows with the primary_id. You can use the foreach loop

if (sizeof($users)>0){
       foreach($users as $user_id){
	   $sql="DELETE FROM <tablename> WHERE primary_id='$user_id'";

5. Similarly connect the primary id to another page where you can dynamically generate the forms to update the data for the selected records.

Please let me know if you need any help with the code.

<input type="checkbox" name="state[]" value="NE">

<input type="checkbox" name="state[]" value="IA">

<input type="checkbox" name="state[]" value="MO">

So in your case your script should loop through all the elements in the area to see if the box was checked or not.

For example:

foreach ($state as $statename)
echo "$statename is checked";


Good luck!

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.