richclever Posted July 26, 2007 Share Posted July 26, 2007 Hi all, I have been trying to figure this one out and have come up against a brick wall although I know it should be relatively simple. I have a form that passes an array to a php script from a multiple select box that is created dynamically. If a user deselects an item then I want to delete the record from the database but am having a big problem with it. The table in the dbase is quite simple with just three fields: id classid formid Basically, the form send through a classid and a formid value and I want to delete any records that have a classid that are not in the form array and have a formid which is passed as a hidden value. I suppose really what I want is to know how to see if a classid is not in the array that is passed. Hope that makes sense. Sorry I don't have any code but I can't get it even nearly right so what I have been playing with wouldn't be any use. Thanks, Richard Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 26, 2007 Share Posted July 26, 2007 I hope i got the concept right. Also i didnt try the code because i didnt have the database but i hope it gives the idea $values = $_POST['select']; //get the array from the multiple select $results = @mysql_query("SELECT * FROM table") or die(); while($rows = mysql_fetch_array($results){ for($i=0; $i<count($values); $i++){ //a loop to get all the array values if($rows['id'] == $values[$i]){ //if the curret id is finded in the array then exit and do nothing $deleteRow = false; exit; } else{ //if it is not finded then it will delete $deleteRow = true; } } if($deleteRow == true){ $queryDelete = "DELETE FROM table WHERE id='{$rows['id']}'"; } } Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 26, 2007 Share Posted July 26, 2007 Couldn't you just use in_array()? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 26, 2007 Share Posted July 26, 2007 Rather than the "Hands up anyone who's not here" approach, it's easier if the user selects items to be deleted. Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 26, 2007 Share Posted July 26, 2007 Couldn't you just use in_array()? Didnt know that. It shortens the code a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.