469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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
Sep 18 '06 #1
5 23250

Vojta wrote:
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)) {} ?

Sep 18 '06 #2
On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
<ry**@centrum.cz>
<ee***********@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).
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Sep 18 '06 #3
Hello Iulian, thank you for your reply.

!is_null($registered) is allways evaluated as TRUE

Vojta

"iulian.ilea" <iu*********@gmail.compíse v diskusním príspevku
news:11**********************@i3g2000cwc.googlegro ups.com...
>
Vojta wrote:
>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)) {} ?

Sep 19 '06 #4
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" <jn******@yahoo.com.aupíse v diskusním príspevku
news:7h********************************@4ax.com...
On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
<ry**@centrum.cz>
<ee***********@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).
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------

Sep 19 '06 #5
On Tue, 19 Sep 2006 11:32:08 +0200, in comp.lang.php "Vojta"
<ry**@centrum.cz>
<ee**********@ns.felk.cvut.czwrote:
>| 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
>| ((boolean)$registered) as true
| (!is_null($registered)) as true
This would return $registered=0 as true.
>| (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
}
>| "Jeff North" <jn******@yahoo.com.aupíse v diskusním príspevku
| news:7h********************************@4ax.com...
| On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
| <ry**@centrum.cz>
| <ee***********@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).
| ---------------------------------------------------------------
| jn******@yourpantsyahoo.com.au : Remove your pants to reply
| ---------------------------------------------------------------
|
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Sep 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Yulia Yegenov | last post: by
3 posts views Thread by kingofkolt | last post: by
5 posts views Thread by glakk | last post: by
reply views Thread by jnam | last post: by
reply views Thread by markwalsen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.