Minase Posted August 19, 2008 Share Posted August 19, 2008 dont know the best title but here is what i must do but cant foreach($_POST as $a => $b){ if(preg_match("/x/",$a) && $b == 'y'){ $id = str_replace("x","",$a); $note_query = $db->query("DELETE FROM `" . DBPREFIX . "messages` WHERE `ID` != '".$id."' AND `ReciverID` = '".$_SESSION['user_id']."' "); } } the problem is that it delete all mesages. it is normal cause it execute multiple querys with diferent ID like if 2 messages and 2 selected for not deleting DELETE FROM messages WHERE ID != 1; DELETE FROM messages WHERE ID != 2; it will automatically delete both of them,dont have an ideea how to do it so it will work normally. thanks Link to comment https://forums.phpfreaks.com/topic/120376-solved-syntax-problem/ Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 DELETE FROM messages WHERE ID != 1 AND ID != 2 ; Link to comment https://forums.phpfreaks.com/topic/120376-solved-syntax-problem/#findComment-620213 Share on other sites More sharing options...
Minase Posted August 19, 2008 Author Share Posted August 19, 2008 i must use foreach whatever will be. Link to comment https://forums.phpfreaks.com/topic/120376-solved-syntax-problem/#findComment-620218 Share on other sites More sharing options...
moselkady Posted August 19, 2008 Share Posted August 19, 2008 You need to do it all in one query. This example will nor work: DELETE FROM messages WHERE ID != 1; DELETE FROM messages WHERE ID != 2; The first query deletes all (including id 2) except id 1 then the second deletes id 1. I think you can modify your code to something like this: <?php foreach($_POST as $a => $b){ if(preg_match("/x/",$a) && $b == 'y'){ $ids[] = str_replace("x","",$a); } } $id = join(",", $ids); $note_query = $db->query("DELETE FROM `" . DBPREFIX . "messages` WHERE `ID` NOT IN (".$id.") AND `ReciverID` = '".$_SESSION['user_id']."' "); ?> Link to comment https://forums.phpfreaks.com/topic/120376-solved-syntax-problem/#findComment-620279 Share on other sites More sharing options...
Minase Posted August 19, 2008 Author Share Posted August 19, 2008 thank you very much Link to comment https://forums.phpfreaks.com/topic/120376-solved-syntax-problem/#findComment-620370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.