?
Solved

mysql php

Posted on 2012-08-29
10
Medium Priority
?
391 Views
Last Modified: 2012-09-06
If I make set a mysql database field to NULL, is it possible to still have the default value as a blank space instead of a value of NULL ?
When I try this the NULL value always reappears

If it is not possible to do this, how do I stop the value of "NULL" from appearing in my webpage records?
0
Comment
Question by:doctorbill
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38346336
Depending on how you are retrieving and displaying the values Null should display as a space anyway.

Are you specifically having the problem of null displaying or are you asking how to prevent this in advance.
0
 

Author Comment

by:doctorbill
ID: 38346349
NULL is displaying. I am sure it did not do this a few weeks ago
Also, Can I stop NULL being entered as a default
0
 

Author Comment

by:doctorbill
ID: 38346425
sorry - my mistake. Just realised that my csv file import had a bunch of NULL values in it
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38346470
Ok - problem solved or is there still a question?
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 38347266
You could also add an if then statement if this was happening
if ($value = NULL) {
$value = 0;
}
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38347349
@nanharbison I think you meant
if ($value == NULL) {
  $value=0;
}

Open in new window

but not necessary because NULL equates to space anyway and he wanted a space not a 0
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 38347396
OOPS, right, sorry!
0
 
LVL 30

Accepted Solution

by:
Olaf Doschke earned 2000 total points
ID: 38347418
Should I add to the confusion?

If you import CSV, default values don't have an impact anyway, do they? Default values of fields are only set in case you do an INSERT INTO a table without specifying a field in the list of fields to insert into. A CSV import would only set default values, if a row of the CSV has less values than a table has fields, if that doesn't even error.

I assume you didn't realised the NULL values where coming from CSV, though, and you assumed data was coming another way. Otherwise you would have a misunderstanding of NULLs in CSV meaning to set a field to it's default. There is no such functionality.

It would actually be an idea to add to the CSV standard or even SQL, not by NULL, but perhaps as DEFAULT as a special keyword for the DEFAULT meaning. For example the first field of a table being an AUTO_INCREMENT field id and the next three fields being char, numeric, date, you could import

DEFAULT,text1,99,01/01/1900
DEFAULT,text2,98,01/01/1900

And the server would generate whatever next AUTO_INCREMENT numbers in the first field.

or you could write
INSERT INTO sometable VALUES (DEFAULT,'text1',99,'01/01/1900')
instead of
INSERT INTO sometable (charfield,numericfield,datefield) VALUES ('text',99,'01/01/1900')

Bye, Olaf.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38357883
You can create tables with something like this in the column definitions...

xyz VARCHAR(12) NOT NULL DEFAULT ''

... Then when you SELECT xyz the resulting value in the results set can be something or an empty string.
0
 

Author Closing Comment

by:doctorbill
ID: 38373355
Thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question