JustinK101 Posted August 29, 2007 Share Posted August 29, 2007 Hello, I have a database that has many tables. How can I write php code to loop through all tables and run the following query: LOOP THROUGH ALL TABLES { DELETE FROM {table_name} WHERE deleted = 1; } Link to comment https://forums.phpfreaks.com/topic/67263-code-to-loop-through-tables-and-execute-query/ Share on other sites More sharing options...
trq Posted August 29, 2007 Share Posted August 29, 2007 <?php // connect to and select database. if ($result = mysql_query("SHOW_TABLES")) { if (mysql_num_rows($result)) { while ($table = mysql_fetch_row($result)) { if (mysql_query("DELETE FROM {$table[0]} WHERE deleted = 1")) { echo "Row deletd from {$table[0]}<br />"; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/67263-code-to-loop-through-tables-and-execute-query/#findComment-337411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.