PHP Variable with Array

Posted by Crays on Stack Overflow See other posts from Stack Overflow or by Crays
Published on 2010-05-11T09:49:45Z Indexed on 2010/05/11 10:04 UTC
Read the original article Hit count: 391

Filed under:
|

Hi guys, i'm trying to make a "update user's power" page. It is something similar to those you can find in say, invisionfree forums.

I need it to generate a list of members with checkbox [done] Add an option for it [done]

What i don't know how to do is to update, to say, give all the selected users the selected power.

Then i went searching for something and found most of them uses array to do this, but i never found one that actually explains how it works.

The example i took (with my own modification) was this:

while($row = mysql_fetch_array($result))
{
echo    '<tr>'.$id[]=$rows['id'].'';
echo    '<td width="50px" align="center" class="TableFormCell"><input type="checkbox" name="option[]" /></td>';
echo    '<td width="170px" align="center" class="TableFormCell">'.$row['uname'].'</td>';
echo    '</tr>';
}

I'm not sure what exactly $id[]=$rows['id'] does

I know after the row, my option[] would become an array of option[1], option[2], option[3]

for what power should be given, i've got no problem with that but on how to update the database i'm got no clue...

for($i=0;$i<$count;$i++){
$sql1="UPDATE ninos SET power='$power' WHERE id='$option[$i]'";
$result1=mysql_query($sql1);
}

So Say i have 5 users, Aye, Bee, Cee, Dee, Eee with IDs of 1,2,3,4,5 how can i make it so that my script would run like

$sql1="UPDATE ninos SET power = '$power' Where id='1','2','3','4','5'";

Please help, thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql