create table members
(id int(4) NOT NULL AUTO_INCREMENT,
privNum int(16) default null,
password varchar(32) NOT NULL,
primary key (id));
Then, i import a csv (excel file) but with no value for privNum, but when i do a select, it shows me that privNum has value 0 but i want it to be null.Is there a way to fix this?
Maybe try setting it to =''? The value '0' exists to represent nothing but so then does null. Maybe somehow you're setting it to '0' without realizing it? Otherwise 0 I imagine may equal to false, so you might want to try checking for true or false?
JAB Creations wrote:Maybe try setting it to =''? The value '0' exists to represent nothing but so then does null. Maybe somehow you're setting it to '0' without realizing it? Otherwise 0 I imagine may equal to false, so you might want to try checking for true or false?
Thank you for your quick answer. Can you explain me please? I'm newbie and i did't exactly understand what you told me.
I don't want to chech true or false but i want to show the values in a php file, where i have something like search engine and it prints me for example all integer < 20. And if a value is null i don't want to print it as 0. I hope you understand what i mean.
Null means there is nothing set...nothing found (so it is empty). While '0' represents nothing if you have a row assigned the value of '0' the row is no longer empty.
I recommend setting the default value to '0'. Then in PHP when you process the array simply do not process a record if value equals '0'.
Remember to use ! to say "does not equal" in PHP. So when you look at the data you want to say in English...
If the value does not equal '0' then do something....
JAB Creations wrote:Null means there is nothing set...nothing found (so it is empty). While '0' represents nothing if you have a row assigned the value of '0' the row is no longer empty.
I recommend setting the default value to '0'. Then in PHP when you process the array simply do not process a record if value equals '0'.
Remember to use ! to say "does not equal" in PHP. So when you look at the data you want to say in English...
If the value does not equal '0' then do something....
if ($result['your_row'] != '0') {/* do stuff here */}
My default is '0' but i want it to be null, empty. And when i print the table via php, i want that column to present as empty and not as '0'. I do not want to make a comparison.
CREATE TABLE members(id INT(4) NOT NULL AUTO_INCREMENT,privNum INT(16) DEFAULT '',password VARCHAR(32) NOT NULL,PRIMARY KEY (id));
...then the value will automatically be empty...which should be the same thing as null.
I'm hardly a MySQL guru so it's more if I know what I'm talking about then you knowing how to clarify what you're asking.
I just tried to create a table with a row that has a default value of 'null' and phpMyAdmin said it's not a valid default value...so try removing the default value altogether and it should be blank by default then.
CREATE TABLE members(id INT(4) NOT NULL AUTO_INCREMENT,privNum INT(16) DEFAULT '',password VARCHAR(32) NOT NULL,PRIMARY KEY (id));
...then the value will automatically be empty...which should be the same thing as null.
I'm hardly a MySQL guru so it's more if I know what I'm talking about then you knowing how to clarify what you're asking.
I just tried to create a table with a row that has a default value of 'null' and phpMyAdmin said it's not a valid default value...so try removing the default value altogether and it should be blank by default then.