Page 1 of 1
Checkbox in PHP/MySQL rows
Posted: Tue Feb 03, 2009 11:49 am
by chadlong41
Hi
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
Re: Checkbox in PHP/MySQL rows
Posted: Tue Feb 03, 2009 11:59 am
by mickeyunderscore
If it were me, I'd make a loop to output all of the data, and on each row output a checkbox named value_0...value_n, containing that row's value.
It would then be possible to loop through the $_POST data on the next page and add up all the values that exist.
Re: Checkbox in PHP/MySQL rows
Posted: Tue Feb 03, 2009 12:03 pm
by Skoalbasher
mickeyunderscore wrote:If it were me, I'd make a loop to output all of the data, and on each row output a checkbox named value_0...value_n, containing that row's value.
It would then be possible to loop through the $_POST data on the next page and add up all the values that exist.
Just a side note. You don't have to do a loop to get the sum of an array. It's like arraysum(array) or something like that.
Re: Checkbox in PHP/MySQL rows
Posted: Tue Feb 03, 2009 3:57 pm
by watson516
Skoalbasher wrote:mickeyunderscore wrote:If it were me, I'd make a loop to output all of the data, and on each row output a checkbox named value_0...value_n, containing that row's value.
It would then be possible to loop through the $_POST data on the next page and add up all the values that exist.
Just a side note. You don't have to do a loop to get the sum of an array. It's like arraysum(array) or something like that.
It would be necessary to loop if you did it the way he suggested. Have to check to see if the checkbox is checked before adding the value to the total.
Re: Checkbox in PHP/MySQL rows
Posted: Tue Feb 03, 2009 4:02 pm
by Skoalbasher
watson516 wrote:Skoalbasher wrote:mickeyunderscore wrote:If it were me, I'd make a loop to output all of the data, and on each row output a checkbox named value_0...value_n, containing that row's value.
It would then be possible to loop through the $_POST data on the next page and add up all the values that exist.
Just a side note. You don't have to do a loop to get the sum of an array. It's like arraysum(array) or something like that.
It would be necessary to loop if you did it the way he suggested. Have to check to see if the checkbox is checked before adding the value to the total.
I was thinking about that. But if it's not checked, the value would be "" no? If that's the case, it doesn't matter, wouldn't affect the sum at all right?
Edit: You're right, just went back and read it again.