Jump to content

replacing null mysql table cells with a value


trilbyfish

Recommended Posts

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.

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.

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;

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.

  • 2 weeks later...

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.