trilbyfish Posted March 20, 2008 Share Posted March 20, 2008 im sure there is something to do this, but i cant seem to find it. Is there a way to find all the blank cells in a table and change them to have some text such as 'empty' inside them? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/ Share on other sites More sharing options...
RottNKorpse Posted March 20, 2008 Share Posted March 20, 2008 why would you want to do that? you would be adding unnecessary data to your database but sure it's possible. the following code is NOT a php script...just the SQL. To use the following code you need to run the sql directly into phpMyAdmin or whatever database management system you use. UPDATE `database_name`.`table_name` SET `column_to_change` = 'empty' WHERE `column_to_change` = ''; I didn't give you a php script because if you probably don't want to run this more than once because after you alter them I doubt you would be making any more values be blank. Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-497167 Share on other sites More sharing options...
trilbyfish Posted March 20, 2008 Author Share Posted March 20, 2008 i want to change change empty cells to have something inside them so that i can edit them. thanks for the code Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-497168 Share on other sites More sharing options...
RottNKorpse Posted March 20, 2008 Share Posted March 20, 2008 well most columns that are null are null for a reason so if you don't know whether or not it will affect it negatively I would suggest researching it before doing anything. If you are just putting empty into them that is a complete waste of time and database space because whether it is '' or 'empty' it will do the exact same thing except 'empty' will take up more space and depending on the amount of empty column values that could be a big difference. Anyway, good luck and hope it works out for ya. Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-497175 Share on other sites More sharing options...
Barand Posted March 20, 2008 Share Posted March 20, 2008 why would you want to do that? you would be adding unnecessary data to your database but sure it's possible. the following code is NOT a php script...just the SQL. To use the following code you need to run the sql directly into phpMyAdmin or whatever database management system you use. UPDATE `database_name`.`table_name` SET `column_to_change` = 'empty' WHERE `column_to_change` = ''; I didn't give you a php script because if you probably don't want to run this more than once because after you alter them I doubt you would be making any more values be blank. If they are NULL, you need ... WHERE `column_to_change` IS NULL; Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-497222 Share on other sites More sharing options...
RottNKorpse Posted March 20, 2008 Share Posted March 20, 2008 why would you want to do that? you would be adding unnecessary data to your database but sure it's possible. the following code is NOT a php script...just the SQL. To use the following code you need to run the sql directly into phpMyAdmin or whatever database management system you use. UPDATE `database_name`.`table_name` SET `column_to_change` = 'empty' WHERE `column_to_change` = ''; I didn't give you a php script because if you probably don't want to run this more than once because after you alter them I doubt you would be making any more values be blank. If they are NULL, you need ... WHERE `column_to_change` IS NULL; true but either would work...I thought about updating the code for that but was waiting to see if he would explain explain why he would even want to do that. Maybe I'm clueless but I seriously don't see the point in doing that. Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-497230 Share on other sites More sharing options...
trilbyfish Posted March 31, 2008 Author Share Posted March 31, 2008 i am doing this so that it shows that the table has been printed properly, and that there isnt just missing cells in the table where there isnt anything in. Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-505869 Share on other sites More sharing options...
RottNKorpse Posted March 31, 2008 Share Posted March 31, 2008 well you could do this with a php variable... run sql to pull the values and make an if statement such as if ($variable_example = "") { $variable_example = "empty"; } This would save database space and only increase the script time by about 0.00003 percent. Anyway, I do understand why you did it but I think if you try that you will find that works just as well and doesn't take up any space to do it. Link to comment https://forums.phpfreaks.com/topic/97161-replacing-null-mysql-table-cells-with-a-value/#findComment-505876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.