Jump to content

[SOLVED] Form help required... apply within.


defeated

Recommended Posts

I want to do something and I have no idea how to go about it.

 

I am displaying the contents of my db out into a table. Each line of the table is a result row from mysql with its own id.  I have added a column of checkboxes to the side of the table.

 

I want to be able to select x number of rows via the check boxes and then click a button that sends information to a page to delete all those rows with checked check boxes.

 

Logic has escaped me.

 

I guess I want to turn the table into a form and return an array of all the row id's that are checked...  that way I can do a foreach on the array to delete each one. ???

 

Am I barking up the wrong tree?

 

How would you do it?

Link to comment
Share on other sites

ok, but how do I assign the row id value to the checkbox?

 

echo "<tr><td>".$id."</td><td>".$name."</td><td>".$subject."</td>";
echo "<td><input type='checkbox' name='whatever' /></td></tr>";
echo "<input type='hidden' name='row' value='".$id."' />

how do I associate the checkbox with that particular row?

Link to comment
Share on other sites

JUst Remember to name your array with the appended []

like

<input type="checkbox" name="delarray[]" value="xxx">

where xxx is the id of the row ya want to delete.

this will show up in php as u guessed

<?php $delarray=$_POST['delarray']; ?>

 

Link to comment
Share on other sites

Just a quick note, to get an array returned as the post data set the name field on each of your checkboxes like name="NAME[]" where NAME is the name of the field. The square brackets should make $_POST[NAME] return an array (note that you should still sanity check it before attempting processing in case none are selected).

 

Just seen your update, like this:

echo "<tr><td>".$id."</td><td>".$name."</td><td>".$subject."</td>";
echo "<td><input type='checkbox' name='whatever[]' value=".$id."/></td></tr>";

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.