Forum Moderators: coopster
What I am doing here is get the userid (pri key) and live field from DB, so if its one then checked. So you could have 10 users and select and deselect whatever but when you submit it stores into an array called live with userid assosciated with it
Code:
if (isset($live))
{
// again something needs to be done here
foreach ($live as $var => $value)
echo $value;
mysql_query("update tablename set
live=$value
where user_num=$var");
}
<form>
<td align="center">
<?
if ($DBlive==1)
{
?>
<input type=checkbox name=live[<? echo $DBuser_num?>] value=1 checked>
<?
}
else
{
?> <input type=checkbox name=live[<? echo $DBuser_num?>] value=1>
<?
}
?></td>
</form>
$users=<some query from DB>;
foreach ($users as $userID) {
if (isset($live[$userID])) {
$liveFlag=1;
} else {
$liveflag=0;
}
mysql_query("update tablename set live=$liveFlag
where user_num=$userID");
}
I hope that helps
The $DBuser_num is the userid for each row of the table, which is passed when you select or perhaps deselect so it knows which rows in the DB to change.
if (isset($live))
{
// again something needs to be done here
foreach ($live as $var => $value)
echo $value;
mysql_query("update tablename set
live=$value
where user_num=$var");
}
<form>
$result=mysql_query("select user_num,live from tablename");
while (list($DBuser_num,$DBlive)=mysql_fetch_row($result))
{
<?
if ($DBlive==1)
{
?>
<input type=checkbox name=live[<? echo $DBuser_num?>] value=1 checked>
<?
}
else
{
?> <input type=checkbox name=live[<? echo $DBuser_num?>] value=1>
<?
}
}
?>
</form>
<form>
<?php
$result=mysql_query("select user_num,live from tablename");
while (list($DBuser_num,$DBlive)=mysql_fetch_row($result)){
print("<input type='checkbox' name='live[".$DBuser_num."]' value='1' ".($DBlive?' CHECKED':'').">");
}
?>
</form>