Checkbox in PHP/MySQL rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chadlong41
Forum Newbie
Posts: 3
Joined: Tue Feb 03, 2009 11:33 am

Checkbox in PHP/MySQL rows

Post 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
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Checkbox in PHP/MySQL rows

Post 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.
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Checkbox in PHP/MySQL rows

Post 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.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Checkbox in PHP/MySQL rows

Post 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.
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Checkbox in PHP/MySQL rows

Post 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.
Post Reply