dustydoc Posted June 1, 2008 Share Posted June 1, 2008 Hey, I'm trying to delete from a list of data using the checkbox method, but I'm experiencing problems attempting to match my ID with checkboxs especially as the ID's will be non-sequential before/after any deletion. All attempts failured and seem now very confusted on the issue. Please help?? best N Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Share Posted June 1, 2008 how are you useing it. Show use some code so we can help. Quote Link to comment Share on other sites More sharing options...
dustydoc Posted June 1, 2008 Author Share Posted June 1, 2008 <form method="post" action="delete_docs.php"> <? //$result = mysql_query("SELECT docID FROM docs"); $result = mysql_query("SELECT * FROM docs"); while($rows=mysql_fetch_array($result)){ //$pop = $rows['docID']; //echo $pop; ?> <input type="checkbox" name="done[]" id="<? echo $rows['docID']?>" value="<? echo $rows['docID']?>"> <label for="<? echo $rows['docID'] ?> ";> <? echo $rows['docID'] . ' : ' . $rows['docname']; ?> </label> <br /> <? } ?> <input type="submit" value="DELETE"> <br><br> <? $result = mysql_query("SELECT docID FROM docs"); while($rows=mysql_fetch_array($result)){ $newarray = $rows['docID']; echo $newarray; } ?> Quote Link to comment Share on other sites More sharing options...
dustydoc Posted June 1, 2008 Author Share Posted June 1, 2008 Stuck from here on in, im manage to get values out but attempting to either pass them into an array/string, i found impossible, maybe you can hep Paul. Thanks for your reply. best N Quote Link to comment Share on other sites More sharing options...
Barand Posted June 1, 2008 Share Posted June 1, 2008 give all c.boxes a name like "delID[]" and a value of the record ID on that row <input type="checkbox" name="delID[]" value="$id"> <input type="checkbox" name="delID[]" value="$id"> <input type="checkbox" name="delID[]" value="$id"> Only selected c.boxes are posted. To process $ids = join (',', $_POST['delID']); $sql = "DELETE FROM tablename WHERE id IN ($ids)"; Quote Link to comment Share on other sites More sharing options...
dustydoc Posted June 1, 2008 Author Share Posted June 1, 2008 hey Barand, thanks for your time man. Though i keep getting an error on the join (bad conditons or something?), plus the numbers have dissapeared due to using an alias. heres what i've updated to: <form method="post" action="delete_doc.php"> <? $id=$HTTP_POST_VARS['docID']; $result = mysql_query("SELECT * FROM docs"); while($rows=mysql_fetch_array($result)){ ?> <input type="checkbox" name="delID[]" value="$id"> <? echo $rows[$id] . ' : ' . $rows['docname']; ?> <br /> <? } $ids = join (',', $_POST['delID']); $sql = "DELETE FROM docs WHERE docID IN ($ids)"; mysql_query($sql); ?> <input type="submit" value="DELETE"> <br><br> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Barand Posted June 1, 2008 Share Posted June 1, 2008 this bit belongs in delete_doc.php, not in the form $ids = join (',', $_POST['delID']); $sql = "DELETE FROM docs WHERE docID IN ($ids)"; mysql_query($sql); The values for the checkboxes need to be that row's id <input type="checkbox" name="delID[]" value="<?php echo $rows['id']?>"> Quote Link to comment Share on other sites More sharing options...
dustydoc Posted June 1, 2008 Author Share Posted June 1, 2008 Sorted Barand, it finally works!!!!! THanks so much best N 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.