Forum Moderators: coopster
For all,
update members set approved = 1;
(But you probably already knew that . . . )
Note I have a 1, not "yes" or "no." These are textual values with a boolean definition. Set your field to tinyint(1) or boolean for this field, not yes or no. 0 = no, 1 = yes. This will make your DB faster.
If it's a selective update, something like this should work, baby-code for logic only.
select id,fname,lname,approved from members;
Now build checkboxes for unapproved members,
using the record id as a unique handle.
while ($row=mysql_fetch_array($result)) {
print $row['fname'] . ' ' . $row['lname'];
if ($row['approved']==1) { print "approved"; }
else {
$chk_name='approved_' . $row['id'];
print "<input type=\"checkbox\" name=\"$chk_name\" id=\"$chk_name\" value=\"1\">";
}
}
foreach ($_POST as $key=>$value) {
if (preg_match('/^approve\_\d+$/',$key)) {
list($tag,$id) = explode('_',$key);
// VERY IMPORTANT! This must be a number.
if (! ($id > 0)) { die("oops! id is not a valid id!"); }
$query = "update members set approved=1 where id=$id";
// Do it!
}
}
Edit: Meh. You'll probably prefer to use array names for checkboxes, inherent in PHP, I like to see what I'm generating and hang a name on it . . . concept is the same though.
[edited by: rocknbil at 9:14 pm (utc) on Dec. 12, 2009]
update table set field='value' where username='one' or username='two';
but it might be easier (or not) to use "in set"
update table set field='value' where user_id in (1,2,5,7);
Note that using "in" against text values will only work if the first part of the text is in the term:
select * from table where field in ('John','Joe','Mary');
Johnny
Joey
SallyJoe <-- fails