Presto-X Posted September 25, 2008 Share Posted September 25, 2008 Hello Guys, I'm trying to delete all rows in a table where a column's content is equal 0. This table holds a course roster with all of the students that have signed up if their status is set to 0 that means they have not paid, 99% will be set to 1 but I want a way for the end user to be able to clean up the table of bad checkouts where the student was not able to sign up for one reason or another. This is the code that I'm trying to use: $query = "DELETE FROM jos_courses_roster WHERE status='0'"; I'm not sure if I have to loop this or what I thought I would ask on here what would be the best way to go about this, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/ Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 Try taking the quotes off of the 0 in the query Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650007 Share on other sites More sharing options...
AndyB Posted September 25, 2008 Share Posted September 25, 2008 That single query will delete ALL records that match the WHERE ... vroom .... oh, maybe I should have backed up my database before I did that, just in case The quotes don't hurt at all. Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650010 Share on other sites More sharing options...
Presto-X Posted September 25, 2008 Author Share Posted September 25, 2008 Thanks for the replys guys, $query = "DELETE FROM jos_courses_roster WHERE status=0"; Is not working either Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650071 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 1) Are you sure there are entries in the db with status = 0? 2) You should probably post more code dealing with the database calls in addition to just the query. Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650102 Share on other sites More sharing options...
Presto-X Posted September 25, 2008 Author Share Posted September 25, 2008 Yes I'm sure there are entries with 0 there are 4 of them, this is my code: if($_GET['clean']=="students"){ $query = "DELETE FROM jos_courses_roster WHERE status='0'"; mysql_query($query); echo "Deletion Complete!"; } and this is the link that I'm using to call it: index2.php?option=com_courses&act=configure&clean=students Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650208 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 Do this for error debugging: mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650220 Share on other sites More sharing options...
Presto-X Posted September 25, 2008 Author Share Posted September 25, 2008 Odd very odd, is this not almost the same code that I was using? now it's working lol if($_GET['clean']=="students"){ $query = "DELETE FROM jos_courses_roster WHERE status='0'"; mysql_query($query) or die(mysql_error()); echo '<div class="message">Deletion Complete!</div>'; } Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650271 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 I would also use mysql_affected_rows() to tell the user how many records were deleted. Quote Link to comment https://forums.phpfreaks.com/topic/125712-solved-im-trying-to-delete-all-rows-where-a-columns-content-is-equal-0/#findComment-650274 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.