By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Need some guidance with ENUM (logical) fields in MySQL

P: n/a
Hello all;

I have used dBASE, and other computer languages/databases, for years. They
all have a logical field type. However, the version of MySQL used by the ISP
hosting my site does not support a "logical" field type.

It does support ENUM and I have set some up in a couple of tables that
accept the values 'T' and 'F'. Sometimes they work like a logical field:

if ($myrow['new']) echo 'New';
else echo 'NOT new';

and other times I must use:

if ($myrow['new'] == 'T') echo 'New';
else echo 'NOT New';

I've been searching google and have only come up with some basic info --
such as use ENUM that allow '0' and '1'.

Before, I go off changing everything, can someone provide some insight in
using ENUM fields as logical and/or point me to a few good articles/web
pages?

TIA.

Charles...


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
You can try

SELECT (new AND 1) as show FROM yourdatabase

If I'm correct

0 = first entry
1 = second entry
2 = 3rd entry
3 = 4th entry
...
If you use SET you can have multiple selected:

0 = none selected
1 = first item selected
2 =second item selected
3 = first & second item selected
4 = 3th item selected
5 = 1st + 3rd ..
6 = 2nd + 3rd
7 = 1st+2nd+3rd .

....

Maybe this helps.

or you can try:

SELECT (new="New") as show FROM yourdatabase
show==0 if not equal
show==1 if equal

:) Hope this helps a bit
Wouter

"Charles Crume" <cc@charlescrumesoftware.com> wrote in message
news:Ui*******************@fe2.columbus.rr.com...
: Hello all;
:
: I have used dBASE, and other computer languages/databases, for years. They
: all have a logical field type. However, the version of MySQL used by the
ISP
: hosting my site does not support a "logical" field type.
:
: It does support ENUM and I have set some up in a couple of tables that
: accept the values 'T' and 'F'. Sometimes they work like a logical field:
:
: if ($myrow['new']) echo 'New';
: else echo 'NOT new';
:
: and other times I must use:
:
: if ($myrow['new'] == 'T') echo 'New';
: else echo 'NOT New';
:
: I've been searching google and have only come up with some basic info --
: such as use ENUM that allow '0' and '1'.
:
: Before, I go off changing everything, can someone provide some insight in
: using ENUM fields as logical and/or point me to a few good articles/web
: pages?
:
: TIA.
:
: Charles...
:
:
:
:
: ---
: Outgoing mail is certified Virus Free.
: Checked by AVG anti-virus system (http://www.grisoft.com).
: Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
:
:
Jul 20 '05 #2

P: n/a
By the way..

Why don't you just:

ENUM('New','NOT New')

and then just echo the value ;)

Wouter
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl...
: You can try
:
: SELECT (new AND 1) as show FROM yourdatabase
:
: If I'm correct
:
: 0 = first entry
: 1 = second entry
: 2 = 3rd entry
: 3 = 4th entry
: ..
:
:
: If you use SET you can have multiple selected:
:
: 0 = none selected
: 1 = first item selected
: 2 =second item selected
: 3 = first & second item selected
: 4 = 3th item selected
: 5 = 1st + 3rd ..
: 6 = 2nd + 3rd
: 7 = 1st+2nd+3rd .
:
: ...
:
: Maybe this helps.
:
: or you can try:
:
: SELECT (new="New") as show FROM yourdatabase
:
:
: show==0 if not equal
: show==1 if equal
:
::) Hope this helps a bit
: Wouter
:
:
:
: "Charles Crume" <cc@charlescrumesoftware.com> wrote in message
: news:Ui*******************@fe2.columbus.rr.com...
:: Hello all;
::
:: I have used dBASE, and other computer languages/databases, for years.
They
:: all have a logical field type. However, the version of MySQL used by the
: ISP
:: hosting my site does not support a "logical" field type.
::
:: It does support ENUM and I have set some up in a couple of tables that
:: accept the values 'T' and 'F'. Sometimes they work like a logical field:
::
:: if ($myrow['new']) echo 'New';
:: else echo 'NOT new';
::
:: and other times I must use:
::
:: if ($myrow['new'] == 'T') echo 'New';
:: else echo 'NOT New';
::
:: I've been searching google and have only come up with some basic info --
:: such as use ENUM that allow '0' and '1'.
::
:: Before, I go off changing everything, can someone provide some insight in
:: using ENUM fields as logical and/or point me to a few good articles/web
:: pages?
::
:: TIA.
::
:: Charles...
::
::
::
::
:: ---
:: Outgoing mail is certified Virus Free.
:: Checked by AVG anti-virus system (http://www.grisoft.com).
:: Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
::
::
:
:
Jul 20 '05 #3

P: n/a
Hi;

Thanks for the reply, but I have no idea what you are talking about. Logical
field can nont have first, second, third, and fourth entries (AFAIK).

Charles...
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl...
You can try

SELECT (new AND 1) as show FROM yourdatabase

If I'm correct

0 = first entry
1 = second entry
2 = 3rd entry
3 = 4th entry
..
If you use SET you can have multiple selected:

0 = none selected
1 = first item selected
2 =second item selected
3 = first & second item selected
4 = 3th item selected
5 = 1st + 3rd ..
6 = 2nd + 3rd
7 = 1st+2nd+3rd .

...

Maybe this helps.

or you can try:

SELECT (new="New") as show FROM yourdatabase
show==0 if not equal
show==1 if equal

:) Hope this helps a bit
Wouter

"Charles Crume" <cc@charlescrumesoftware.com> wrote in message
news:Ui*******************@fe2.columbus.rr.com...
: Hello all;
:
: I have used dBASE, and other computer languages/databases, for years. They : all have a logical field type. However, the version of MySQL used by the
ISP
: hosting my site does not support a "logical" field type.
:
: It does support ENUM and I have set some up in a couple of tables that
: accept the values 'T' and 'F'. Sometimes they work like a logical field:
:
: if ($myrow['new']) echo 'New';
: else echo 'NOT new';
:
: and other times I must use:
:
: if ($myrow['new'] == 'T') echo 'New';
: else echo 'NOT New';
:
: I've been searching google and have only come up with some basic info --
: such as use ENUM that allow '0' and '1'.
:
: Before, I go off changing everything, can someone provide some insight in : using ENUM fields as logical and/or point me to a few good articles/web
: pages?
:
: TIA.
:
: Charles...
:
:
:
:
: ---
: Outgoing mail is certified Virus Free.
: Checked by AVG anti-virus system (http://www.grisoft.com).
: Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
:
:

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
Jul 20 '05 #4

P: n/a
Because I need a standard logical field to use in different situations
besides just "new" and "NOT new" (that was an example).
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl...
By the way..

Why don't you just:

ENUM('New','NOT New')

and then just echo the value ;)

Wouter
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl...
: You can try
:
: SELECT (new AND 1) as show FROM yourdatabase
:
: If I'm correct
:
: 0 = first entry
: 1 = second entry
: 2 = 3rd entry
: 3 = 4th entry
: ..
:
:
: If you use SET you can have multiple selected:
:
: 0 = none selected
: 1 = first item selected
: 2 =second item selected
: 3 = first & second item selected
: 4 = 3th item selected
: 5 = 1st + 3rd ..
: 6 = 2nd + 3rd
: 7 = 1st+2nd+3rd .
:
: ...
:
: Maybe this helps.
:
: or you can try:
:
: SELECT (new="New") as show FROM yourdatabase
:
:
: show==0 if not equal
: show==1 if equal
:
::) Hope this helps a bit
: Wouter
:
:
:
: "Charles Crume" <cc@charlescrumesoftware.com> wrote in message
: news:Ui*******************@fe2.columbus.rr.com...
:: Hello all;
::
:: I have used dBASE, and other computer languages/databases, for years.
They
:: all have a logical field type. However, the version of MySQL used by the : ISP
:: hosting my site does not support a "logical" field type.
::
:: It does support ENUM and I have set some up in a couple of tables that
:: accept the values 'T' and 'F'. Sometimes they work like a logical field: ::
:: if ($myrow['new']) echo 'New';
:: else echo 'NOT new';
::
:: and other times I must use:
::
:: if ($myrow['new'] == 'T') echo 'New';
:: else echo 'NOT New';
::
:: I've been searching google and have only come up with some basic info -- :: such as use ENUM that allow '0' and '1'.
::
:: Before, I go off changing everything, can someone provide some insight in :: using ENUM fields as logical and/or point me to a few good articles/web
:: pages?
::
:: TIA.
::
:: Charles...
::
::
::
::
:: ---
:: Outgoing mail is certified Virus Free.
:: Checked by AVG anti-virus system (http://www.grisoft.com).
:: Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
::
::
:
:

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
Jul 20 '05 #5

P: n/a
Well..

In MySQL you can have more logical.

For an Multiplpe choise exam:
ENUM('A','B','C','D')
or for en enquette:
ENUM('Yes','No','no opinion')

The first option has logical value 0, the second logical value 1.
The 3rd option has logical value 2, the 4th option logical value 3.

It's not that hard..

It's even handy in some situations.
I normally use:

file_online: 'no','yes','not tested'

with the default value to 'not tested'
In MySQL you can access the value like a logical.
But the result will give you one of the values of the ENUM definition.
I think it's more readble that way than just using 0 and 1 or true and
false.
Vist http://dev.mysql.com/doc/mysql/en/ENUM.html
if it's not yet clear to you.
Wouter
"Charles Crume" <cc@charlescrumesoftware.com> wrote in message
news:yq*******************@fe2.columbus.rr.com...
: Hi;
:
: Thanks for the reply, but I have no idea what you are talking about.
Logical
: field can nont have first, second, third, and fourth entries (AFAIK).
:
: Charles...
:
:
: "Wouter" <no******************@djwice.com> wrote in message
: news:cm**********@news.tudelft.nl...
: > You can try
: >
: > SELECT (new AND 1) as show FROM yourdatabase
: >
: > If I'm correct
: >
: > 0 = first entry
: > 1 = second entry
: > 2 = 3rd entry
: > 3 = 4th entry
: > ..
: >
: >
: > If you use SET you can have multiple selected:
: >
: > 0 = none selected
: > 1 = first item selected
: > 2 =second item selected
: > 3 = first & second item selected
: > 4 = 3th item selected
: > 5 = 1st + 3rd ..
: > 6 = 2nd + 3rd
: > 7 = 1st+2nd+3rd .
: >
: > ...
: >
: > Maybe this helps.
: >
: > or you can try:
: >
: > SELECT (new="New") as show FROM yourdatabase
: >
: >
: > show==0 if not equal
: > show==1 if equal
: >
: > :) Hope this helps a bit
: > Wouter
: >
: >
: >
: > "Charles Crume" <cc@charlescrumesoftware.com> wrote in message
: > news:Ui*******************@fe2.columbus.rr.com...
: > : Hello all;
: > :
: > : I have used dBASE, and other computer languages/databases, for years.
: They
: > : all have a logical field type. However, the version of MySQL used by
the
: > ISP
: > : hosting my site does not support a "logical" field type.
: > :
: > : It does support ENUM and I have set some up in a couple of tables that
: > : accept the values 'T' and 'F'. Sometimes they work like a logical
field:
: > :
: > : if ($myrow['new']) echo 'New';
: > : else echo 'NOT new';
: > :
: > : and other times I must use:
: > :
: > : if ($myrow['new'] == 'T') echo 'New';
: > : else echo 'NOT New';
: > :
: > : I've been searching google and have only come up with some basic
info --
: > : such as use ENUM that allow '0' and '1'.
: > :
: > : Before, I go off changing everything, can someone provide some insight
: in
: > : using ENUM fields as logical and/or point me to a few good
articles/web
: > : pages?
: > :
: > : TIA.
: > :
: > : Charles...
: > :
: > :
: > :
: > :
: > : ---
: > : Outgoing mail is certified Virus Free.
: > : Checked by AVG anti-virus system (http://www.grisoft.com).
: > : Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
: > :
: > :
: >
: >
:
:
: ---
: Outgoing mail is certified Virus Free.
: Checked by AVG anti-virus system (http://www.grisoft.com).
: Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
:
:
Jul 20 '05 #6

P: n/a
Sorry I made a mistake.

The first value is 1.
'' = 0

:)
Wouter
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl...
: Well..
:
: In MySQL you can have more logical.
:
: For an Multiplpe choise exam:
: ENUM('A','B','C','D')
: or for en enquette:
: ENUM('Yes','No','no opinion')
:
: The first option has logical value 0, the second logical value 1.
: The 3rd option has logical value 2, the 4th option logical value 3.
:
: It's not that hard..
:
: It's even handy in some situations.
: I normally use:
:
: file_online: 'no','yes','not tested'
:
: with the default value to 'not tested'
:
:
: In MySQL you can access the value like a logical.
: But the result will give you one of the values of the ENUM definition.
:
:
: I think it's more readble that way than just using 0 and 1 or true and
: false.
: Vist http://dev.mysql.com/doc/mysql/en/ENUM.html
: if it's not yet clear to you.
:
:
: Wouter
:
:
: "Charles Crume" <cc@charlescrumesoftware.com> wrote in message
: news:yq*******************@fe2.columbus.rr.com...
:: Hi;
::
:: Thanks for the reply, but I have no idea what you are talking about.
: Logical
:: field can nont have first, second, third, and fourth entries (AFAIK).
::
:: Charles...
::
::
:: "Wouter" <no******************@djwice.com> wrote in message
:: news:cm**********@news.tudelft.nl...
:: > You can try
:: >
:: > SELECT (new AND 1) as show FROM yourdatabase
:: >
:: > If I'm correct
:: >
:: > 0 = first entry
:: > 1 = second entry
:: > 2 = 3rd entry
:: > 3 = 4th entry
:: > ..
:: >
:: >
:: > If you use SET you can have multiple selected:
:: >
:: > 0 = none selected
:: > 1 = first item selected
:: > 2 =second item selected
:: > 3 = first & second item selected
:: > 4 = 3th item selected
:: > 5 = 1st + 3rd ..
:: > 6 = 2nd + 3rd
:: > 7 = 1st+2nd+3rd .
:: >
:: > ...
:: >
:: > Maybe this helps.
:: >
:: > or you can try:
:: >
:: > SELECT (new="New") as show FROM yourdatabase
:: >
:: >
:: > show==0 if not equal
:: > show==1 if equal
:: >
:: > :) Hope this helps a bit
:: > Wouter
:: >
:: >
:: >
:: > "Charles Crume" <cc@charlescrumesoftware.com> wrote in message
:: > news:Ui*******************@fe2.columbus.rr.com...
:: > : Hello all;
:: > :
:: > : I have used dBASE, and other computer languages/databases, for years.
:: They
:: > : all have a logical field type. However, the version of MySQL used by
: the
:: > ISP
:: > : hosting my site does not support a "logical" field type.
:: > :
:: > : It does support ENUM and I have set some up in a couple of tables
that
:: > : accept the values 'T' and 'F'. Sometimes they work like a logical
: field:
:: > :
:: > : if ($myrow['new']) echo 'New';
:: > : else echo 'NOT new';
:: > :
:: > : and other times I must use:
:: > :
:: > : if ($myrow['new'] == 'T') echo 'New';
:: > : else echo 'NOT New';
:: > :
:: > : I've been searching google and have only come up with some basic
: info --
:: > : such as use ENUM that allow '0' and '1'.
:: > :
:: > : Before, I go off changing everything, can someone provide some
insight
:: in
:: > : using ENUM fields as logical and/or point me to a few good
: articles/web
:: > : pages?
:: > :
:: > : TIA.
:: > :
:: > : Charles...
:: > :
:: > :
:: > :
:: > :
:: > : ---
:: > : Outgoing mail is certified Virus Free.
:: > : Checked by AVG anti-virus system (http://www.grisoft.com).
:: > : Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
:: > :
:: > :
:: >
:: >
::
::
:: ---
:: Outgoing mail is certified Virus Free.
:: Checked by AVG anti-virus system (http://www.grisoft.com).
:: Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
::
::
:
:
Jul 20 '05 #7

P: n/a
HI Wouter;
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl...
Well..

In MySQL you can have more logical.
Very interesting -- I've never come across this before in any of the
programming languages I've used.

For an Multiplpe choise exam:
ENUM('A','B','C','D')
or for en enquette:
ENUM('Yes','No','no opinion')

The first option has logical value 0, the second logical value 1.
The 3rd option has logical value 2, the 4th option logical value 3.

It's not that hard..
Well, I'm sure having difficulty understanding "the 3rd option has logical
value 2, the 4th...". Logicals have always been 0/1, T/F, on/off for me.
Maybe the light will come on after working on this a little longer.

It's even handy in some situations.
Even though I'm having difficuly grasping the concept, I can easily see this
(not sure why, guess it's just my gut instinct after years and years of
programming).

I normally use:

file_online: 'no','yes','not tested'

with the default value to 'not tested'
I understand this -- in Visual dBASE 'not-tested' would essentially be null
(a value has never been set).

In MySQL you can access the value like a logical.
But the result will give you one of the values of the ENUM definition.
I think it's more readble that way than just using 0 and 1 or true and
false.
Vist http://dev.mysql.com/doc/mysql/en/ENUM.html
if it's not yet clear to you.


I'm going to re-read this.

Thanks again.

Charles...

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/04
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.