tags:

views:

58

answers:

1
+1  A: 

First, this doesn't make much sense (the assignment doesn't output anything printable):

echo '<tr>'.$id[]=$rows['id'].'';

This does the same yet it's clearer (the first line, since in a loop, will go on storing all the ids in an array):

$id[] = $rows['id'];
echo '<tr>';

UPDATE: Anyways there's no need to store the ids in an array here, just use $row['id'] to print the user identifier in the option value (right now no value is set):

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

The form action script will receive a $_POST['option'] variable containing the selected ids. An example of how it can be used:

$ids = array();
// input filtering: convert all values to integers
foreach($_POST['option'] as $id)
{
    $ids[] = (int)$id;
}    
if(!empty($ids)) {
    // if there's at least one selected user
    $sql1 = "UPDATE ninos SET power = '$power' Where id IN (" . implode(',', $ids) . ")";
    // execute the query (...)
}
nuqqsa
After submitting ,this is how i get the ID right?$id = $_POST['id'];then i have this as you stated$sql1="UPDATE ninos SET power='$power' WHERE id IN (".implode(',', $id).")";but i've got thisWarning: implode() [function.implode]: Invalid arguments passed
Crays
The second parameter of implode must be an array. This code assumes that $id is an array containing the user identifiers, NOT a $_POST variable. The array is generated through the instruction $id[] = $rows['id']; within the loop that iterates the query results.
nuqqsa
Oh, I misunderstood your question, now I get it also includes the post part. Let me update the answer.
nuqqsa
Thanks for the reply, but it doesn't seem to work.Do you have a working example i could have a look at :) ?
Crays
Can you explain what's not working?
nuqqsa
I've updated my post with my full script so you probably can have a better view. I've no idea what's wrong with it, it goes through everything but when i check my records, nothing is changed :(.
Crays
Thanks for your effort, i've got it done, i tried all over with simple testing and it worked. So i transferred that into it :)
Crays
Great, congrats.
nuqqsa