View Full Version : Display blank field in table instead of "0"?
eyebum
March 13th, 2009, 03:44 PM
Hey there,
I am using mysql and php 5.
I have a lot of score data to display in tables. they are results from competitions. In these results, a Zero ('0') is different than no score.
I have the score fields set as decimal, as they are added and such. When I display the results, any fields that have no score default to displaying a '0'. I would like them to display nothing (blank) or a hyphen (-).
Has anyone encountered a way to do this with decimal or integer fields?
Thanks,
Chris
NeoDreamer
March 14th, 2009, 02:20 PM
I suppose you used PHPMyAdmin to create your database. You should change that score columns attribute from NOT NULL to NULL. This allows a "no score" to be stored.
eyebum
March 15th, 2009, 03:11 AM
I suppose you used PHPMyAdmin to create your database. You should change that score columns attribute from NOT NULL to NULL. This allows a "no score" to be stored.
Well, I use PHPMyAdmin as a short cut to make quick changes to my live database, but the main tool I use to create it is Navicat for Mysql. I sometimes use Sequel Pro as well.
Anyhow, I changed every decimal field's attribute to NULL, with a default value of NULL. I re-imported the data, and again, the zeros. ugh.
If I go into PHPMyAdmin, browse the content, and edit a field with a 0 and replace it with NULL, then YES, it does show up as empty. But my database is 1500 rows, with 64 fields! and over half of them are supposed to be blank!! So I have no clue..can't seem to get a default NULL value to stick...
Thanks
blazes
March 15th, 2009, 03:22 PM
Make sure to test first, but what about something like:
UPDATE contests SET score = NULL WHERE score = '0'
eyebum
March 15th, 2009, 11:55 PM
Make sure to test first, but what about something like:
UPDATE contests SET score = NULL WHERE score = '0'
Hey!
Well, yep, that worked to change the existing scores...(I will have to go back through and put the actual zeros back in, but there won't be too many...).
I am hoping that new scores will be blank unless they are an actual score (or an actual 0), but if they don't, then this will work to change lots of scores quickly...Thanks Blazes!
Chris
:alien:
blazes
March 16th, 2009, 07:17 PM
If the column is now set to NULL, then all new entries should be blank. The only reason they didn't change, is because when it was NOT NULL, it defaulted to 0, so that's what it stayed. You should be good to go now.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.