stopblackholes Posted May 12, 2008 Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105222-solved-need-help-deleting-multiple-rows-from-mysql-with-php/ Share on other sites More sharing options...
The Little Guy Posted May 12, 2008 Share Posted May 12, 2008 remove the "+=" and use ".=" Link to comment https://forums.phpfreaks.com/topic/105222-solved-need-help-deleting-multiple-rows-from-mysql-with-php/#findComment-538788 Share on other sites More sharing options...
Psycho Posted May 12, 2008 Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105222-solved-need-help-deleting-multiple-rows-from-mysql-with-php/#findComment-538791 Share on other sites More sharing options...
stopblackholes Posted May 12, 2008 Author Share Posted May 12, 2008 Thanks guys! ah i always confuse += operator with .= yeah the way you do it looks cleaner. Link to comment https://forums.phpfreaks.com/topic/105222-solved-need-help-deleting-multiple-rows-from-mysql-with-php/#findComment-538797 Share on other sites More sharing options...
corbin Posted May 12, 2008 Share Posted May 12, 2008 += adds numbers, and .= strings. Remember the + as in addition and . as in period and it's easier ;p. Link to comment https://forums.phpfreaks.com/topic/105222-solved-need-help-deleting-multiple-rows-from-mysql-with-php/#findComment-538800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.