FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » Database discussions » Zero values in fields
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Zero values in fields [message #19820] Tue, 07 September 2004 00:50 Go to next message
Abraxa is currently offline  Abraxa   United States
Messages: 72
Registered: August 2004
Location: Germany
Karma: 0
Member
Heya peeps =)

I got a relatively simple problem I guess but I can't figure it out for the life of me.
The deal is that I have zeroes in the fields of a table and when I do a query for those fields the values passed to the PHP variables are empty instead of having a zero in them.

Anyone got an idea about what I can do?

-Abraxa
Re: Zero values in fields [message #19823 is a reply to message #19820] Tue, 07 September 2004 12:15 Go to previous messageGo to next message
dataj1998 is currently offline  dataj1998   Germany
Messages: 31
Registered: June 2004
Location: Germany
Karma: 0
Member

It's a difference if you have zeroes (0) or NULL in the field.
What are the types of the fields? Int? Varchar?

If you wanna get the 0 back, they have to be Int or a Varchar where the "string" 0 is in.
Re: Zero values in fields [message #19839 is a reply to message #19820] Sat, 11 September 2004 01:49 Go to previous messageGo to next message
Abraxa is currently offline  Abraxa   United States
Messages: 72
Registered: August 2004
Location: Germany
Karma: 0
Member
Thanks for the hints! =)

I fiddled around with MySQL and set the field properties of that column to NOT NULL and lowered the length of the length field (at least I think that's all I did, it was a couple days ago).
I just checked again and to my surprise the query does return the zero values now...

Could it have been the NOT NULL option? Sorry, I'm a beginner in MySQL and couldn't find anything about the exact behavior of that option in the MySQL documentation =\

-Soeren
Re: Zero values in fields [message #19842 is a reply to message #19820] Sun, 12 September 2004 14:32 Go to previous messageGo to next message
dataj1998 is currently offline  dataj1998   Germany
Messages: 31
Registered: June 2004
Location: Germany
Karma: 0
Member

The solution with the option "NOT NULL" should do the whole job.

If a field is defined to be not null, you should always get a value back. But please be careful: You should set a default value for that field. If you insert a record and leave out a field with the option set and you don't have a default value, your insert will fail.
Re: Zero values in fields [message #19845 is a reply to message #19820] Sun, 12 September 2004 19:36 Go to previous messageGo to next message
Abraxa is currently offline  Abraxa   United States
Messages: 72
Registered: August 2004
Location: Germany
Karma: 0
Member
Thanks a ton, mate!

People like you are who make coding worthwhile and fun - cause you saved me lots of time figuring out why my INSERTs wouldn't o through cause I unknowingly had the exact problem in my table that you made me aware of =D

-Soeren
Re: Zero values in fields [message #19848 is a reply to message #19820] Sun, 12 September 2004 21:37 Go to previous messageGo to next message
dataj1998 is currently offline  dataj1998   Germany
Messages: 31
Registered: June 2004
Location: Germany
Karma: 0
Member

np
Re: Zero values in fields [message #20217 is a reply to message #19848] Sun, 03 October 2004 10:50 Go to previous messageGo to next message
alansmith is currently offline  alansmith   United Kingdom
Messages: 49
Registered: February 2004
Location: Seaton Devon
Karma: 0
Member
can you make a change to not null when you already have it set differently. Does it affect every table in the database if you only have one db?
Re: Zero values in fields [message #20229 is a reply to message #20217] Mon, 04 October 2004 13:17 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Yes, but it won't affect existing values.

FUDforum Core Developer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 2 Fud Forums, Can I combine users
Next Topic: Determining when to use INSERT or UPDATE
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 20:06:37 GMT 2024

Total time taken to generate the page: 0.01732 seconds