Jump to content

[SOLVED] Need help Deleting multiple rows from mysql with php


stopblackholes

Recommended Posts

I cant figure out what the problem is.  i know it has to do with  $deletelist +=  line.

 

if i echo just the value it has correct value but if i try and add it to the string of values for the mysql query i get 00000 no '1','2' ect.

 

  <?php     $deletelist="";
                $deletecounter=0;
			print_r($_POST['checkbox']); //// array of selected checkboxes
    foreach($_POST['checkbox'] as $key => $value)
    {
         echo  $value; /// comes back with correct value
                  echo  $deletelist += "'".$value."'"; // does not! comes back 0 
                    if($deletecounter>0){$deletelist += ","; }
                    $deletecounter++;
                   
    }
   mysql_query("DELETE FROM posts WHERE post_id in ($deletelist)")or die(mysql_error());

?>

 

Link to comment
Share on other sites

This will be a little more efficient:

<?php

   $deletelist= "'" . implode("', '", $_POST['checkbox']) . "'";
   $query = "DELETE FROM posts WHERE post_id in ($deletelist)";

   mysql_query($query)or die(mysql_error()."<br />QUERY: $query");

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.