Connecting Tech Pros Worldwide Help | Site Map

PHP, MySQL and BIT field

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 18th, 2006, 01:35 PM
Vojta
Guest
 
Posts: n/a
Default PHP, MySQL and BIT field

Please can somebody give me an advice?

my MySQL table contains bit field

Registered BIT(1) NOT NULL DEFAULT 0

I read records using

$result = mysql_query('SELECT * FROM MyUsers');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$registered = $row['Registered'];

Command "echo $registered;" shows nothing or rectangles depending on the
value, it's ok. But I do not know how to use it in IF statements or so.
Whatever I try does not work. How can I work with such values in PHP?

Thank you in advance! Vojta



  #2  
Old September 18th, 2006, 01:55 PM
iulian.ilea
Guest
 
Posts: n/a
Default Re: PHP, MySQL and BIT field


Vojta wrote:
Quote:
Please can somebody give me an advice?
>
my MySQL table contains bit field
>
Registered BIT(1) NOT NULL DEFAULT 0
>
I read records using
>
$result = mysql_query('SELECT * FROM MyUsers');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$registered = $row['Registered'];
>
Command "echo $registered;" shows nothing or rectangles depending on the
value, it's ok. But I do not know how to use it in IF statements or so.
Whatever I try does not work. How can I work with such values in PHP?
>
Thank you in advance! Vojta
I'm not sure if this works, but have you tryed if
(!is_null($registered)) {} ?

  #3  
Old September 18th, 2006, 03:15 PM
Jeff North
Guest
 
Posts: n/a
Default Re: PHP, MySQL and BIT field

On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
<ryvo@centrum.cz>
<eem7p4$24u1$1@ns.felk.cvut.czwrote:
Quote:
>| Please can somebody give me an advice?
>|
>| my MySQL table contains bit field
>|
>| Registered BIT(1) NOT NULL DEFAULT 0
>|
>| I read records using
>|
>| $result = mysql_query('SELECT * FROM MyUsers');
>| $row = mysql_fetch_array($result, MYSQL_ASSOC);
>| $registered = $row['Registered'];
>|
>| Command "echo $registered;" shows nothing or rectangles depending on the
>| value, it's ok. But I do not know how to use it in IF statements or so.
>| Whatever I try does not work. How can I work with such values in PHP?
>|
>| Thank you in advance! Vojta
>|
The value is either 0000 or 0001 - not to be confused with ascii(0) or
ascii(1).
---------------------------------------------------------------
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
  #4  
Old September 19th, 2006, 09:15 AM
Vojta
Guest
 
Posts: n/a
Default Re: PHP, MySQL and BIT field

Hello Iulian, thank you for your reply.

!is_null($registered) is allways evaluated as TRUE

Vojta

"iulian.ilea" <iulian.ilea@gmail.compíse v diskusním príspevku
news:1158588261.314245.233520@i3g2000cwc.googlegro ups.com...
Quote:
>
Vojta wrote:
Quote:
>Please can somebody give me an advice?
>>
>my MySQL table contains bit field
>>
>Registered BIT(1) NOT NULL DEFAULT 0
>>
>I read records using
>>
>$result = mysql_query('SELECT * FROM MyUsers');
>$row = mysql_fetch_array($result, MYSQL_ASSOC);
>$registered = $row['Registered'];
>>
>Command "echo $registered;" shows nothing or rectangles depending on the
>value, it's ok. But I do not know how to use it in IF statements or so.
>Whatever I try does not work. How can I work with such values in PHP?
>>
>Thank you in advance! Vojta
I'm not sure if this works, but have you tryed if
(!is_null($registered)) {} ?
>

  #5  
Old September 19th, 2006, 09:25 AM
Vojta
Guest
 
Posts: n/a
Default Re: PHP, MySQL and BIT field

Hello Jeff, thank you for reply. I tried following expressions, they are
allways evalueted:

($registered == 1) as false
($registered == '1') as false
($registered == '0001') as false
((boolean)$registered) as true
(!is_null($registered)) as true

(integer)$registered prints allways 0

Please, how exactly should I work with $register variable?

Vojta

"Jeff North" <jnorthau@yahoo.com.aupíse v diskusním príspevku
news:7hetg2lvqqjk111k6j9snuvi7djkcmbsr5@4ax.com...
Quote:
On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
<ryvo@centrum.cz>
<eem7p4$24u1$1@ns.felk.cvut.czwrote:
>
Quote:
>>| Please can somebody give me an advice?
>>|
>>| my MySQL table contains bit field
>>|
>>| Registered BIT(1) NOT NULL DEFAULT 0
>>|
>>| I read records using
>>|
>>| $result = mysql_query('SELECT * FROM MyUsers');
>>| $row = mysql_fetch_array($result, MYSQL_ASSOC);
>>| $registered = $row['Registered'];
>>|
>>| Command "echo $registered;" shows nothing or rectangles depending on the
>>| value, it's ok. But I do not know how to use it in IF statements or so.
>>| Whatever I try does not work. How can I work with such values in PHP?
>>|
>>| Thank you in advance! Vojta
>>|
>
The value is either 0000 or 0001 - not to be confused with ascii(0) or
ascii(1).
---------------------------------------------------------------
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------

  #6  
Old September 20th, 2006, 01:25 AM
Jeff North
Guest
 
Posts: n/a
Default Re: PHP, MySQL and BIT field

On Tue, 19 Sep 2006 11:32:08 +0200, in comp.lang.php "Vojta"
<ryvo@centrum.cz>
<eeodev$9b0$1@ns.felk.cvut.czwrote:
Quote:
>| Hello Jeff, thank you for reply. I tried following expressions, they are
>| allways evalueted:
>|
>| ($registered == 1) as false
>| ($registered == '1') as false
>| ($registered == '0001') as false
Huh??? False = 0 whereas True != 0
Quote:
>| ((boolean)$registered) as true
>| (!is_null($registered)) as true
This would return $registered=0 as true.
Quote:
>| (integer)$registered prints allways 0
>|
>| Please, how exactly should I work with $register variable?
>|
>| Vojta
how about:
if( !is_null($registered) )
{
if( $registered 0 )
//--- do true stuff
else
//--- do false stuff
}
Quote:
>| "Jeff North" <jnorthau@yahoo.com.aupíse v diskusním príspevku
>| news:7hetg2lvqqjk111k6j9snuvi7djkcmbsr5@4ax.com...
>| On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
>| <ryvo@centrum.cz>
>| <eem7p4$24u1$1@ns.felk.cvut.czwrote:
>| >
>| >>| Please can somebody give me an advice?
>| >>|
>| >>| my MySQL table contains bit field
>| >>|
>| >>| Registered BIT(1) NOT NULL DEFAULT 0
>| >>|
>| >>| I read records using
>| >>|
>| >>| $result = mysql_query('SELECT * FROM MyUsers');
>| >>| $row = mysql_fetch_array($result, MYSQL_ASSOC);
>| >>| $registered = $row['Registered'];
>| >>|
>| >>| Command "echo $registered;" shows nothing or rectangles depending on the
>| >>| value, it's ok. But I do not know how to use it in IF statements or so.
>| >>| Whatever I try does not work. How can I work with such values in PHP?
>| >>|
>| >>| Thank you in advance! Vojta
>| >>|
>| >
>| The value is either 0000 or 0001 - not to be confused with ascii(0) or
>| ascii(1).
>| ---------------------------------------------------------------
>| jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
>| ---------------------------------------------------------------
>|
---------------------------------------------------------------
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.