Jump to content

Archived

This topic is now archived and is closed to further replies.

alan543

Checkbox in PHP/MySQL rows

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

×

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.