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
Checkbox in PHP/MySQL rows
Moderator: General Moderators
-
mickeyunderscore
- Forum Contributor
- Posts: 129
- Joined: Sat Jan 31, 2009 9:00 am
- Location: UK
Re: Checkbox in PHP/MySQL rows
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.
It would then be possible to loop through the $_POST data on the next page and add up all the values that exist.
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Checkbox in PHP/MySQL rows
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.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.
Re: Checkbox in PHP/MySQL rows
Skoalbasher wrote: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.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.
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.
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Checkbox in PHP/MySQL rows
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?watson516 wrote:Skoalbasher wrote: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.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.
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.
Edit: You're right, just went back and read it again.