Jump to content


Photo

Checkbox in PHP/MySQL rows


  • Please log in to reply
4 replies to this topic

#1 alan543

alan543
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 March 2006 - 01:02 PM

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

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 14 March 2006 - 01:51 PM

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

$checkboxarray = $_POST['mycheckbox'];

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

unchecked boxes are automatically ignored anyway.

cheers

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 alan543

alan543
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 March 2006 - 03:24 PM

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

#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 14 March 2006 - 06:28 PM

[!--quoteo(post=354911:date=Mar 14 2006, 03:24 PM:name=alan543)--][div class=\'quotetop\']QUOTE(alan543 @ Mar 14 2006, 03:24 PM) View Post[/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)
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#5 alan543

alan543
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 March 2006 - 04:21 PM

It's ok I managed to do a workaround. Thanks for your help anyway.

Cheers,
Alan




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users