PHP, MySQL and BIT field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vojta

    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


  • iulian.ilea

    #2
    Re: PHP, MySQL and BIT field


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

    Comment

    • Jeff North

      #3
      Re: PHP, MySQL and BIT field

      On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
      <ryvo@centrum.c z>
      <eem7p4$24u1$1@ 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).
      ---------------------------------------------------------------
      jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
      ---------------------------------------------------------------

      Comment

      • Vojta

        #4
        Re: PHP, MySQL and BIT field

        Hello Iulian, thank you for your reply.

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

        Vojta

        "iulian.ile a" <iulian.ilea@gm ail.compíse v diskusním príspevku
        news:1158588261 .314245.233520@ 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)) {} ?
        >

        Comment

        • Vojta

          #5
          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)$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" <jnorthau@yahoo .com.aupíse v diskusním príspevku
          news:7hetg2lvqq jk111k6j9snuvi7 djkcmbsr5@4ax.c om...
          On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
          <ryvo@centrum.c z>
          <eem7p4$24u1$1@ 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).
          ---------------------------------------------------------------
          jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
          ---------------------------------------------------------------

          Comment

          • Jeff North

            #6
            Re: PHP, MySQL and BIT field

            On Tue, 19 Sep 2006 11:32:08 +0200, in comp.lang.php "Vojta"
            <ryvo@centrum.c z>
            <eeodev$9b0$1@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" <jnorthau@yahoo .com.aupíse v diskusním príspevku
            >| news:7hetg2lvqq jk111k6j9snuvi7 djkcmbsr5@4ax.c om...
            >| On Mon, 18 Sep 2006 15:42:55 +0200, in comp.lang.php "Vojta"
            >| <ryvo@centrum.c z>
            >| <eem7p4$24u1$1@ 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).
            >| ---------------------------------------------------------------
            >| jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
            >| ---------------------------------------------------------------
            >|
            ---------------------------------------------------------------
            jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
            ---------------------------------------------------------------

            Comment

            Working...