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());

?>

 

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");

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.