ack Posted November 13, 2010 Share Posted November 13, 2010 Forgive me if I am using the word "globally" incorrectly... I want to reset the content of a particular field in all rows of a table to a specific value, I was thinking of nesting a query inside a query for the same table, but was not sure that this would work: ... $query = "SELECT * FROM music WHERE picked >'0'"; $result = mysql_query($query) or die ("Couldn't execute query."); /* reset the picked field to zero (0) */ while ($row = mysql_fetch_array($result)) { $picked = 0; $query= "UPDATE music SET picked='$picked' WHERE title='$title'"; $selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error()); } ... Is this the correct approach or is there a better way of doing this? Link to comment https://forums.phpfreaks.com/topic/218570-globally-resetting-a-table-field/ Share on other sites More sharing options...
litebearer Posted November 13, 2010 Share Posted November 13, 2010 a simple update with needing a loop can accomplish your goal http://www.tizag.com/mysqlTutorial/mysqlupdate.php Link to comment https://forums.phpfreaks.com/topic/218570-globally-resetting-a-table-field/#findComment-1133776 Share on other sites More sharing options...
PFMaBiSmAd Posted November 13, 2010 Share Posted November 13, 2010 $query= "UPDATE music SET picked= 0"; $selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error()); If this is a one time thing, simply execute that query in your favorite database management program - UPDATE music SET picked= 0; Link to comment https://forums.phpfreaks.com/topic/218570-globally-resetting-a-table-field/#findComment-1133782 Share on other sites More sharing options...
ack Posted November 13, 2010 Author Share Posted November 13, 2010 Thanks again, PFMaBiSmAd I successfully wrapped your code example into a maintenence page so that I can now reset the table when necessary. I spent quite a while trying to find a solution and I suspected that I was going down the wrong road... I have been researching PHP classes in my area and - from this question - it appears that spending some time in the classroom will help a lot. too! I appreciate everyone's help and advice over the last few days! Cordially, Ack (not the ASCII control code, BTW. I was amazed that that handle had not been snagged onto here. Usually that stuff is long gone...) Link to comment https://forums.phpfreaks.com/topic/218570-globally-resetting-a-table-field/#findComment-1133823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.