473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

checkbox values stored in mysql

I have a series of checkboxes and need to store their values in a MySQL
table.

I'm wondering what data type people recommend:

varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"

Maybe it depends on the usage or maybe it doesn't matter and/or is a choice
of personal preference.

Comments welcome.

p.s. Is there a reference page somewhere that discusses the various data
types and their recommended uses?
Jul 17 '05 #1
4 3233
Xenophobe wrote:
I have a series of checkboxes and need to store their values in a MySQL
table.

I'm wondering what data type people recommend:

varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"

Maybe it depends on the usage or maybe it doesn't matter and/or is a choice
of personal preference.

Comments welcome.

p.s. Is there a reference page somewhere that discusses the various data
types and their recommended uses?


True/False 0/1 will basically be personal preference - and it is a lot more
efficient to store 1 byte (tinyint) vs. 5.

--
Michael Austin.
Consultant - Available.
:)
Jul 17 '05 #2
I tend to agree.

Speaking of efficiency, do you prefer to use varchar? I've been told in the
past to treat all data as text UNLESS it's a number that requires
calculation.

"Michael Austin" <ma*****@firstdbasource.com> wrote in message
news:Zo*****************@newssvr22.news.prodigy.co m...
Xenophobe wrote:
I have a series of checkboxes and need to store their values in a MySQL
table.

I'm wondering what data type people recommend:

varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"

Maybe it depends on the usage or maybe it doesn't matter and/or is a choice of personal preference.

Comments welcome.

p.s. Is there a reference page somewhere that discusses the various data
types and their recommended uses?
True/False 0/1 will basically be personal preference - and it is a lot

more efficient to store 1 byte (tinyint) vs. 5.

--
Michael Austin.
Consultant - Available.
:)

Jul 17 '05 #3
On Tue, 13 Jul 2004 15:54:00 GMT, "Xenophobe" <xe*******@planetx.com> wrote:
I have a series of checkboxes and need to store their values in a MySQL
table.

I'm wondering what data type people recommend:

varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"

Maybe it depends on the usage or maybe it doesn't matter and/or is a choice
of personal preference.


Largely comes down to personal preference, I think.

I use 'T'/'F' mainly just because that's the convention at the company where I
work.

0/1 has the advantage that you can use the value as a Boolean value in PHP or
Perl etc.

I wouldn't use anything longer than a byte, though, so that rules out the
wordier 'Yes'/'No' 'True'/'False' options.

In fact in Oracle, which I mostly work with, 1 is two bytes in its internal
storage scheme, whereas 'T' is one byte (unless you're using UTF16 as the
database character set).

MySQL's TINYINT type guarantees a single byte for the number though.

Should be wary of trying to be clever and forming bitmasks in a single column
just to start saving bytes, since you're breaking normalisation rules if you go
down that route.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #4
Xenophobe wrote:
I tend to agree.

Speaking of efficiency, do you prefer to use varchar? you need to review the MySQL docs concerning the CHAR/VARCHAR data types at:

http://dev.mysql.com/doc/mysql/en/CHAR.html
and
http://dev.mysql.com/doc/mysql/en/Si...n_changes.html

There is a table that shows what the difference between CHAR and VARCHAR - read
them carefully. If you don't understand, just ask.

I've been told in the
past to treat all data as text UNLESS it's a number that requires
calculation.

<snip>

Whoever gave you that sage advice obviously should not be designing databases.
There are many different reasons to use different datatypes. The least of which
is efficiency. Yes, I did mention that before, but I also took into account
what you were trying to achieve.

<RANT mode=annoyed>
One of my pet peeves is the fact that too many programmers are creating
"databases" (and I use the term very loosely here), and then can't understand
why their database doesn't perform. Sometimes the problem is also the database
engine they have chosen to employ. MySQL and PostgreSQL are fine for some
things, but may not be "enterprise class". And expecting an interpreted
language like PHP or Python etc... to be scaldingly fast is just asking for
trouble. wheeew...
</RANT>

--
Michael Austin.
Consultant - Available.
OracleRdb, OracleRDBMS, MySQL DBA and OpenVMS, Linux System Administrator
Web Administrator and Generalist
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bill | last post by:
I have a catalog of books which need to be categorized into different groups. Some of the books can be listed under more than one category. I'm creating a page where I can assign a group of books...
4
by: Bee | last post by:
Hi everyone, I'm having trouble accessing a Mysql database containing checkbox data that is posted from a form. I use the serialize function to store the checkbox values in an array (in a column...
4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
0
by: deathtospam | last post by:
A few weeks ago, I created a Classic ASP page that connects to a machine with SQL Server installed on it, prompts the user to select a database on that server, then lists all of user-created stored...
4
by: khyati30 | last post by:
hello , here , i have arised problem in php & mysql . i have one form which has 3 checkboxes .if i m selected checkbox then the radiogroup is enable and i m selected one value. if i m...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.