473,902 Members | 4,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('SE LECT * FROM MyUsers');
$row = mysql_fetch_arr ay($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 23711

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('SE LECT * FROM MyUsers');
$row = mysql_fetch_arr ay($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($regi stered)) {} ?

Sep 18 '06 #2
On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
<ry**@centrum.c z>
<ee***********@ ns.felk.cvut.cz 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('SE LECT * FROM MyUsers');
| $row = mysql_fetch_arr ay($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******@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Sep 18 '06 #3
Hello Iulian, thank you for your reply.

!is_null($regis tered) is allways evaluated as TRUE

Vojta

"iulian.ile a" <iu*********@gm ail.compíse v diskusním príspevku
news:11******** **************@ i3g2000cwc.goog legroups.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('SE LECT * FROM MyUsers');
$row = mysql_fetch_arr ay($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($regi stered)) {} ?

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)$regi stered) as true
(!is_null($regi stered)) as true

(integer)$regis tered 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.c om...
On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
<ry**@centrum.c z>
<ee***********@ ns.felk.cvut.cz 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('SE LECT * FROM MyUsers');
| $row = mysql_fetch_arr ay($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******@yourpa ntsyahoo.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.c z>
<ee**********@n s.felk.cvut.czw rote:
>| 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)$regi stered) as true
| (!is_null($regi stered)) as true
This would return $registered=0 as true.
>| (integer)$regis tered prints allways 0
|
| Please, how exactly should I work with $register variable?
|
| Vojta
how about:
if( !is_null($regis tered) )
{
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.c om...
| On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
| <ry**@centrum.c z>
| <ee***********@ ns.felk.cvut.cz 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('SE LECT * FROM MyUsers');
| >>| $row = mysql_fetch_arr ay($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******@yourpa ntsyahoo.com.au : Remove your pants to reply
| ---------------------------------------------------------------
|
---------------------------------------------------------------
jn******@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Sep 20 '06 #6

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

Similar topics

2
3200
by: Yulia Yegenov | last post by:
I have a query that looks like this: (I insert the date created with the php date function) $status = "Active"; //(I cannot use the mysql timestamp function for other reason). $curdate = date("m/j/Y H:i"); $owner = "not assigned"; @ $db_connect = mysql_connect("localhost", "$db_username", "$db_password");
3
6466
by: kingofkolt | last post by:
All, What do you recommend as the best type of field for a timestamp in a MySQL database? I've considered varchar(10) or INT but I'm not sure what is the best, most efficient, and most reliable field type. Thanks. - JP
5
1944
by: glakk | last post by:
I have a problem of migrating a database from one host to another. I can't do a dump on the source server. The only access I have is thru queries. So it looks like I'm going to have to query all the tables and insert to the destination. I'm trying to come up with a general solution to this problem which uses queries to determine the structure of the source db, and create the tables on the destination, which I've already done using the...
0
1782
by: jnam | last post by:
I am having a problem putting a certain length of text from a textarea form element into a mySQL field. The field is set to LONGTEXT but I get an error. Whne I shorten the text it writes to the DB with no problem. I am getting a long strng, perhaps 200 characters or more into a variable that will then be written to an mySQL DB but I am getting an error in the DB. How can I set the field to accept more than 400 or 700 text characters? ...
3
2670
by: bobmct | last post by:
In my feeble attempt to keep track of login session timeouts I have the following code in my login section of my program: $sql = "UPDATE subscriber SET _sessexp = 'DATE_ADD(NOW(),INTERVAL 15 MINUTES)' WHERE _userid = '$_userid' LIMIT 1"; and when run I see NO ERRORS. However, either the field in the DB doesn't change OR this expression is generating a value of '0' for the _sessexp
1
1772
by: Roach | last post by:
Hello all ! (my first post) First its safe to assume that I have no idea what I am doing because you would be correct. My problem is, I am working in a simple paypal ipn script and I have stored t or f (true or false) in mysql my_config field my_field Now in the ipn script I need to know if that info in my_config >my_field is t or f I have tried many variations like:
0
2041
by: markwalsen | last post by:
I've been quite pleased with linking via MySQL Connector / ODBC 3.51 from Access to a remote MySQL database. However, I haven't figured out how to establish the link between a Data Type = Attachment field in Access and some corresponding MySQL field (BLOB, BINARY, I'm not sure what would work). Depending on what SQL datatype I define for this field, when I import that field (link) into the Access table, the Access data type is either...
1
2600
by: aragorn73 | last post by:
I've a database with some fields. I want to add some email addresses that I've into a txt file, separated by comma, into filed "email", appending to existing one. How can I do ?
0
2414
by: ffenton | last post by:
I have a problem with text being inserted into a mysql database containing hidden characters. The text arrives there via multiple stages. Basically it is copied from Ms Word into an Ms Access rich text field (I'm pretty sure this is where the problem originates from). From here it is written to a .txt file and uploaded via ftp to the webserver where php inserts it into the mysql table. The problem becomes noticable when it's displayed on a...
2
3098
by: jewellman | last post by:
Hello. I have been reading over some posts that deal with my issue and although I couldn't get my issue to work I did read some very good information. I have created a mySQL table that I will use to populate vehicle inventory with. My fields are- Primary_Key, Year, Make/Model, Description, Mileage, Price, and Image. The problem I am having is with the Image field. I can't get the image to display from the browser. I read on here...
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10499
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8047
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.