lindm Posted June 8, 2008 Share Posted June 8, 2008 Trying to build a tiny but effective script that removes database data for all columns beginning with cx. It is relating to storing checkbox status. Since an unchecked checkbox doesn't send data I need to "reset" all stored checkbox values before sending new checkbox data. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/109297-php-mysql-find-and-update-columns-beginning-with/ Share on other sites More sharing options...
rarebit Posted June 8, 2008 Share Posted June 8, 2008 Do you need to do this in sql... $sql = "UPDATE t SET x = y WHERE x LIKE '%cx' "; or php... $x = 0; if(isset($_POST['x'])) { $x = 1; } Quote Link to comment https://forums.phpfreaks.com/topic/109297-php-mysql-find-and-update-columns-beginning-with/#findComment-560627 Share on other sites More sharing options...
lindm Posted June 8, 2008 Author Share Posted June 8, 2008 Tried the query but get unknown column error. I have say 20 columns all with the name beginning with cx: cxTEST cxTEST2 cxTEST3 etc Is there a simple query to empty all columns? I tried UPDATE table SET x ='' WHERE x LIKE 'cx%' but no go. Quote Link to comment https://forums.phpfreaks.com/topic/109297-php-mysql-find-and-update-columns-beginning-with/#findComment-560643 Share on other sites More sharing options...
rarebit Posted June 8, 2008 Share Posted June 8, 2008 if you used that statement as is then yeah, you will (more than probably) get an 'unknown column error'... change it to whatever is relevant to your table... but your right the % should be on the right... Quote Link to comment https://forums.phpfreaks.com/topic/109297-php-mysql-find-and-update-columns-beginning-with/#findComment-560725 Share on other sites More sharing options...
lindm Posted June 9, 2008 Author Share Posted June 9, 2008 But isn't that impossible. I want x to refer to all columns that begin with cx. Instead of writing SET cx1 = '', cx2 ='' etc.. I want to write SET all columns that begin with cx to ''. Can't see how your query can work... Quote Link to comment https://forums.phpfreaks.com/topic/109297-php-mysql-find-and-update-columns-beginning-with/#findComment-561314 Share on other sites More sharing options...
fenway Posted June 10, 2008 Share Posted June 10, 2008 You'll need the information_schema tables in MySQL 5 to do that... Quote Link to comment https://forums.phpfreaks.com/topic/109297-php-mysql-find-and-update-columns-beginning-with/#findComment-562394 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.