jakebur01 Posted February 25, 2009 Share Posted February 25, 2009 I am trying to delete all the rows that do not have a value. The fields were originally formated in excel - accounting with 2 decimal places. Is there a better way to get rid of all of the rows that do not have valid prices? mysql_query("DELETE FROM {$tablename} WHERE $dealer=''"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='$-'"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='-'"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='$0.00'"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='0'"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='0.00'"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='0.0'"); mysql_query("DELETE FROM {$tablename} WHERE $dealer='$0.0'"); Link to comment https://forums.phpfreaks.com/topic/146936-solved-a-better-way-to-delete-rows/ Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 You could just use the IN statement and have 1 query: mysql_query("DELETE FROM {$tablename} WHERE $dealer IN('', '$-')"); Just add the rest to that IN statement following the same format. Link to comment https://forums.phpfreaks.com/topic/146936-solved-a-better-way-to-delete-rows/#findComment-771410 Share on other sites More sharing options...
jakebur01 Posted February 25, 2009 Author Share Posted February 25, 2009 Cool, thanks. Link to comment https://forums.phpfreaks.com/topic/146936-solved-a-better-way-to-delete-rows/#findComment-771417 Share on other sites More sharing options...
Lodius2000 Posted February 25, 2009 Share Posted February 25, 2009 if you used mysqli or a some of the dba's out there you could use a prepared statement, run it through a foreach and do it all with the same query // this method still makes multiple db queries though Link to comment https://forums.phpfreaks.com/topic/146936-solved-a-better-way-to-delete-rows/#findComment-771431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.