Jump to content

Checkbox in PHP/MySQL rows


alan543

Recommended Posts

Hi Folks,
any help appreciated here.

I have a simple Table (Table1) with 3 fields (ID, Date, Value).

So if I query the DB for a certain date it lists the ID and value of all rows with that date. What I need to do is have a checkbox next to each table row and only the ID & Value of the rows that are checked should be posted to the next page where I will do a SUM to add the values together.

Does anyone have any ideas on the best way to do this?

Thanks in advance...

Alan
Link to comment
Share on other sites

make sure all the checkboxes have the same 'name' attribute, but followed by square brackets, ie name="mycheckbox[]"

by default, only the checkboxes that are checked will pass a value to your next script, and the checkbox values can be accessed with

[code]
$checkboxarray = $_POST['mycheckbox'];

foreach ($checkboxarray as $checkvalue)
{
   echo $checkvalue.'<br>';
}
[/code]

unchecked boxes are automatically ignored anyway.

cheers
Link to comment
Share on other sites

[!--quoteo(post=354911:date=Mar 14 2006, 03:24 PM:name=alan543)--][div class=\'quotetop\']QUOTE(alan543 @ Mar 14 2006, 03:24 PM) [snapback]354911[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks for that. That works great for passing the value of the checkbox (i.e. on) But It's the other values in the row that I need to pass on if the checkbox is checked? Any ideas?

Thanks
[/quote]

dont think i'm getting you. if a checkbox is checked, then it's VALUE is passed in the $_POST. if it's not checked, NOTHING is passed. can you be more specific about your problem?

(has been a long day, so maybe i'm missing something simple)
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.