On 06.02.2001 18:09:36 russ wrote:
> Im new to the list, apologies if this has been asked before.
>
> Im developing a backend for a personal site (www.russd.com) using mySQL.
> The site is hosted on NT4 and has myODBC installed, I have some database
access
> working, but I'm looking for a way to implement boolean types.
>
> Using Access/SQL server I can simple do an insert using SQL like the following
> (from within ASP):
>
> INSERT INTO tblMyTable (booleanField) VALUES (" & myBooleanVariant & ");"
Okay, define booleanField to be TinyINT, or maybe ENUM('TRUE', 'FALSE'), but
TinyINT would be a lot easier IMO.
Then for FALSE you'd insert a 0 and for TRUE you'd insert something else.
> values within my ASP code to 1/0. This isn't perfect howevere as its more
code,
Why? Dunno about ASP but since it's from M$ it must be superior to PHP *G* and
in PHP you'd simply do this:
$q = "INSERT INTO tblMyTable (booleanField) VALUES ('" . ( "yes" == "no" ) .
"')";
$rs = mysql_query( $q );
Now booleanField would be set to a FALSE value, or:
$q = "INSERT INTO tblMyTable (booleanField) VALUES ('" . ( "answer to life,
universe and everything" == "42" ) . "')";
$rs = mysql_query( $q );
This time, we'd have set your booleanField to TRUE *G* (well, sorta :]).
$q = "SELECT booleanField FROM tblMyTable WHERE Something=42";
$rs = mysql_query( $q );
$row = mysql_fetch_object( $rs );
if( $row->booleanField ){(
// booleanField is anything but 0, ie. it's TRUE
} else {
// booleanField is 0, ie. it is FALSE
}
In how far is this more code??
> Could anyone suggest a better way of implementing this, or am I missing
> something?
Yeah, you're missing something. In many languages there's no bool data type,
basically, because something like a tinyINT handles this very well.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php