Forum Moderators: coopster

Message Too Old, No Replies

Lots of Changes to a mysql Table

How do I Modify Many User Records With Checkboxes/Combo Boxes?

         

Netvyper

11:39 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Im Realatively new to php, with only a couple of basic sites under my belt...
I've come accross a problem whereby i want to modify the records of all my users in one go. The layout would be all the Usernames Listed, with Checkboxes next to each, and then a Submit Button at the end, with the checkboxes modifying specific columns in my database.

I simply dont know how to go about getting this to happen, short of running a new query for each & every user, this seems kinda silly to me. Can you please point me in the right direction for this?
Many Thanks in Advnace
Netvyper

ergophobe

12:34 am on Jul 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome Netvyper

There was a recent thread on the subject. Check this out

[webmasterworld.com...]

This might be helpful too, but I think you're asking a more advanced question than the one in this post:
[webmasterworld.com...]

Netvyper

1:06 am on Jul 23, 2005 (gmt 0)

10+ Year Member



Thanks, i scrolled back a few pages, but nothing jumped out at me.

The threads help with reguard to the actual database interaction, im still unsure how to define which row of data from the page relates to which row in the table though...

More Thinking required i think :)

ergophobe

2:16 am on Jul 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




unsure how to define which row of data from the page relates to which row in the table though.

You need to get your primary key in there somehow. One way is to use it as the array index for your checkbox as in

<input type="checkbox" name="active[123]">

Then when you process the post data, you can do a foreach

foreach ($_POST['active'] as $key=>$val)
{

$query = UPDATE mytable SET active='1' WHERE user_id = '$key';

}

something like that