Jump to content


Photo

checkbox + sql


  • Please log in to reply
3 replies to this topic

#1 nominator

nominator
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 May 2006 - 08:33 AM

hi, i am doing a member system. at the admin panel which have a list of user, has a checkbox each at the side. I did a loop to display all user from db and set the checkbox value to the id accordingly

$result =mysql_query("Select * from staff");
if($myrow = mysql_fetch_array($result));
{
do{
printf("             <tr>
                <td width=100><span class=text>%s</span></td>
                <td width=100><input type=checkbox name=check value=%s></td>
             </tr>",$myrow[name],$myrow[staff_id]);
             
}while($myrow=mysql_fetch_array($result));
}

then for my action delete,

    if($action == 'delete')
    {
        $check = $_POST['check'];
        connect();
        mysql_query("Delete from staff where staff_id='$check'");
    }

i select a few user to delete, but it only delete one...how can i make it delete whatever i checked.

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 29 May 2006 - 09:19 AM

$result =mysql_query("Select * from staff");
if($myrow = mysql_fetch_array($result));
{
do{
printf("             <tr>
                <td width=100><span class=text>%s</span></td>
                <td width=100><input type=checkbox name=check[] value=%s></td>
             </tr>",$myrow[name],$myrow[staff_id]);
            
}while($myrow=mysql_fetch_array($result));
}

and


if($action == 'delete')
    {
        $check = $_POST['check'];
        connect();
        if(count($check)) {
             $check_id_list = "(".implode(",",$check).")";
             mysql_query("Delete from staff where staff_id in ".$check_id_list);
         }
          
    }

Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 nominator

nominator
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 May 2006 - 09:29 AM

[!--quoteo(post=378026:date=May 29 2006, 04:19 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ May 29 2006, 04:19 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$result =mysql_query("Select * from staff");
if($myrow = mysql_fetch_array($result));
{
do{
printf("             <tr>
                <td width=100><span class=text>%s</span></td>
                <td width=100><input type=checkbox name=check[] value=%s></td>
             </tr>",$myrow[name],$myrow[staff_id]);
            
}while($myrow=mysql_fetch_array($result));
}

and


if($action == 'delete')
    {
        $check = $_POST['check'];
        connect();
        if(count($check)) {
             $check_id_list = "(".implode(",",$check).")";
             mysql_query("Delete from staff where staff_id in ".$check_id_list);
         }
          
    }
[/quote]
not working..


Warning: implode(): Bad arguments. in /home/itecollege/domains/itecollege.com/public_html/stcc/manager.php on line 36

woops..working le..sorry

#4 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 29 May 2006 - 09:31 AM

please try to check if value to $check if passed or not...

echo "<pre>";
print_r($_POST['check']);
echo "</pre>";

put this before connect();

pl let me know what it displays.
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users