equality and TINYINT field?

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

    equality and TINYINT field?

    Hello

    I have a TINYINT(1) field, group1, in a mysql data base and the value
    is 1 but php

    if ($row['group1'] == "1") {

    does not work.

    What should I be writing here?

    Cheers

    Geoff

    PS echoing the group1 value does give 1.
  • Sjoerd

    #2
    Re: equality and TINYINT field?

    On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.no tcomwrote:
    the value is 1 but php
    if ($row['group1'] == "1") {
    does not work.
    This should work. However, if $row['group1'] contains "1 " (one space)
    it does not work. You can use vardump($row['group1']) to determine the
    precise contents and type of the variable.

    What also could be the case is that the if works, but you think it is
    not because something else is broken.

    Comment

    • Jim

      #3
      Re: equality and TINYINT field?

      Geoff Cox wrote:
      Hello
      >
      I have a TINYINT(1) field, group1, in a mysql data base and the value
      is 1 but php
      >
      if ($row['group1'] == "1") {
      >
      does not work.
      >
      What should I be writing here?
      >
      Cheers
      >
      Geoff
      >
      PS echoing the group1 value does give 1.
      Lose the double quotes round 1 ?

      -- Jim.

      Comment

      • Geoff Cox

        #4
        Re: equality and TINYINT field?

        On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sjoerder@gmail .com>
        wrote:
        >On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.no tcomwrote:
        >the value is 1 but php
        >if ($row['group1'] == "1") {
        >does not work.
        >
        >This should work. However, if $row['group1'] contains "1 " (one space)
        >it does not work. You can use vardump($row['group1']) to determine the
        >precise contents and type of the variable.
        This is odd! I am using var_dump and code below which first gives
        group1 as 1 and then var_dump as NULL and then no.

        any idea what is going on?!

        Cheers

        Geoff

        while ($row = mysql_fetch_arr ay($result)) {
        echo $row['user_name'] . " "
        .. $row['group1'] ." "
        .. $row['group2'] . " "
        .. $row['group3'] . " "
        .. $row['group4'] . " "
        .. $row['group5']
        .."<br>";
        }

        echo var_dump($row['group1']);

        if ($row['group1'] == 1) {
        echo "yes" . "<br>";
        } else {
        echo "no" . "<br>";
        }




        >
        >What also could be the case is that the if works, but you think it is
        >not because something else is broken.

        Comment

        • Geoff Cox

          #5
          Re: equality and TINYINT field?

          On Tue, 12 Aug 2008 08:41:48 +0100, Jim <not@this.addre sswrote:
          >Geoff Cox wrote:
          >Hello
          >>
          >I have a TINYINT(1) field, group1, in a mysql data base and the value
          >is 1 but php
          >>
          >if ($row['group1'] == "1") {
          >>
          >does not work.
          >>
          >What should I be writing here?
          >>
          >Cheers
          >>
          >Geoff
          >>
          >PS echoing the group1 value does give 1.
          >
          >Lose the double quotes round 1 ?
          >
          >-- Jim.

          I've tried that Jim - please have a look at my reply to Sjoerd and see
          if you have any thoughts!

          Cheers

          Geoff

          Comment

          • Paul Lautman

            #6
            Re: equality and TINYINT field?

            Geoff Cox wrote:
            On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sjoerder@gmail .com>
            wrote:
            >
            >>On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.no tcomwrote:
            >>the value is 1 but php
            >>if ($row['group1'] == "1") {
            >>does not work.
            >>
            >>This should work. However, if $row['group1'] contains "1 " (one space)
            >>it does not work. You can use vardump($row['group1']) to determine the
            >>precise contents and type of the variable.
            >
            This is odd! I am using var_dump and code below which first gives
            group1 as 1 and then var_dump as NULL and then no.
            Please post the output from
            var_dump($row)


            Comment

            • Geoff Cox

              #7
              Re: equality and TINYINT field?

              On Tue, 12 Aug 2008 10:00:18 +0100, "Paul Lautman"
              <paul.lautman@b tinternet.comwr ote:
              >Geoff Cox wrote:
              >On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sjoerder@gmail .com>
              >wrote:
              >>
              >>>On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.no tcomwrote:
              >>>the value is 1 but php
              >>>if ($row['group1'] == "1") {
              >>>does not work.
              >>>
              >>>This should work. However, if $row['group1'] contains "1 " (one space)
              >>>it does not work. You can use vardump($row['group1']) to determine the
              >>>precise contents and type of the variable.
              >>
              >This is odd! I am using var_dump and code below which first gives
              >group1 as 1 and then var_dump as NULL and then no.
              >
              >Please post the output from
              >var_dump($ro w)
              >
              Paul,

              not much to tell (if I understand you correctly) - I get

              fred 1 0 0 0 0
              NULL
              no

              where NULL refers to $row['group1'] which in the first line is 1?!

              Cheers

              Geoff

              PS the code is

              echo var_dump($row['group1']) . "<br>";
              if ($row['group1'] == 1) {
              echo "yes" . "<br>";
              } else {
              echo "no" . "<br>";
              }

              } else {
              echo mysql_error();
              }

              Comment

              • Paul Lautman

                #8
                Re: equality and TINYINT field?

                Geoff Cox wrote:
                On Tue, 12 Aug 2008 10:00:18 +0100, "Paul Lautman"
                <paul.lautman@b tinternet.comwr ote:
                >
                >>Geoff Cox wrote:
                >>On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd
                >><sjoerder@gma il.comwrote:
                >>>
                >>>>On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.no tcomwrote:
                >>>>the value is 1 but php
                >>>>if ($row['group1'] == "1") {
                >>>>does not work.
                >>>>
                >>>>This should work. However, if $row['group1'] contains "1 " (one
                >>>>space) it does not work. You can use vardump($row['group1']) to
                >>>>determine the precise contents and type of the variable.
                >>>
                >>This is odd! I am using var_dump and code below which first gives
                >>group1 as 1 and then var_dump as NULL and then no.
                >>
                >>Please post the output from
                >>var_dump($row )
                >>
                >
                Paul,
                >
                not much to tell (if I understand you correctly) - I get
                >
                fred 1 0 0 0 0
                NULL
                no
                >
                where NULL refers to $row['group1'] which in the first line is 1?!
                >
                Cheers
                >
                Geoff
                >
                PS the code is
                >
                echo var_dump($row['group1']) . "<br>";
                if ($row['group1'] == 1) {
                echo "yes" . "<br>";
                } else {
                echo "no" . "<br>";
                }
                >
                } else {
                echo mysql_error();
                }
                I asked:
                Please post the output from
                var_dump($row)

                you posted something else.

                Let me try this again:
                Please post the output from
                var_dump($row)

                (Hint, now it is your turn. What you need to do is to READ what I asked and
                to DO what is asked. This is how you get help!)


                Comment

                • Geoff Cox

                  #9
                  Re: equality and TINYINT field?

                  On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
                  <paul.lautman@b tinternet.comwr ote:

                  >>
                  >echo var_dump($row['group1']) . "<br>";
                  >if ($row['group1'] == 1) {
                  >echo "yes" . "<br>";
                  >} else {
                  >echo "no" . "<br>";
                  >}
                  >>
                  >} else {
                  >echo mysql_error();
                  >}
                  >
                  >I asked:
                  >Please post the output from
                  >var_dump($ro w)
                  >
                  >you posted something else.
                  >
                  >Let me try this again:
                  >Please post the output from
                  >var_dump($ro w)
                  Paul,

                  'sorry - kind of watch my lips stupid!

                  I get

                  bool(false)

                  Cheers,

                  Geoff

                  Comment

                  • Geoff Cox

                    #10
                    Re: equality and TINYINT field?

                    On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
                    <paul.lautman@b tinternet.comwr ote:

                    >(Hint, now it is your turn. What you need to do is to READ what I asked and
                    >to DO what is asked. This is how you get help!)

                    Paul

                    this is how I created the table

                    CREATE TABLE best_users (
                    user_name text,
                    group1 tinyint(1),
                    group2 tinyint(1),
                    group3 tinyint(1),
                    group4 tinyint(1),
                    group5 tinyint(1)
                    ) TYPE=MyISAM;

                    --
                    -- Dumping data for table best_docs
                    --

                    INSERT INTO best_users VALUES ('fred',1,0,0,0 ,0);
                    INSERT INTO best_users VALUES ('jill',0,1,0,0 ,1);
                    INSERT INTO best_users VALUES ('jane',1,0,0,0 ,0);
                    INSERT INTO best_users VALUES ('sam',0,1,0,0, 1);
                    INSERT INTO best_users VALUES ('bill',0,0,0,1 ,1);
                    INSERT INTO best_users VALUES ('mary',0,0,1,0 ,0);

                    any clue there?

                    Cheers

                    Geoff

                    PS is using SSH I do a

                    select * from best_users where group1 = 1

                    this works OK and I get records 1 and 3 as I ought....

                    Comment

                    • Paul Lautman

                      #11
                      Re: equality and TINYINT field?

                      Geoff Cox wrote:
                      On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
                      <paul.lautman@b tinternet.comwr ote:
                      >
                      >
                      >>>
                      >>echo var_dump($row['group1']) . "<br>";
                      >>if ($row['group1'] == 1) {
                      >>echo "yes" . "<br>";
                      >>} else {
                      >>echo "no" . "<br>";
                      >>}
                      >>>
                      >>} else {
                      >>echo mysql_error();
                      >>}
                      >>
                      >>I asked:
                      >>Please post the output from
                      >>var_dump($row )
                      >>
                      >>you posted something else.
                      >>
                      >>Let me try this again:
                      >>Please post the output from
                      >>var_dump($row )
                      >
                      Paul,
                      >
                      'sorry - kind of watch my lips stupid!
                      >
                      I get
                      >
                      bool(false)
                      >
                      Cheers,
                      >
                      Geoff
                      You need to execute:
                      $row = mysql_fetch_arr ay($result))
                      var_dump($row)

                      You do not use echo with var_dump


                      Comment

                      • Geoff Cox

                        #12
                        Re: equality and TINYINT field?

                        On Tue, 12 Aug 2008 14:44:29 +0100, "Paul Lautman"
                        <paul.lautman@b tinternet.comwr ote:

                        >You need to execute:
                        >$row = mysql_fetch_arr ay($result))
                        >var_dump($ro w)
                        >
                        >You do not use echo with var_dump

                        OK I see - I get

                        array(12) { [0]= string(4) "fred" ["user_name"]= string(4) "fred"
                        [1]= string(1) "1" ["group1"]= string(1) "1" [2]= string(1) "0"
                        ["group2"]= string(1) "0" [3]= string(1) "0" ["group3"]=>
                        string(1) "0" [4]= string(1) "0" ["group4"]= string(1) "0" [5]=>
                        string(1) "0" ["group5"]= string(1) "0" }

                        Cheers

                        Geoff




                        Comment

                        • Geoff Cox

                          #13
                          Re: equality and TINYINT field?

                          On Tue, 12 Aug 2008 14:44:29 +0100, "Paul Lautman"
                          <paul.lautman@b tinternet.comwr ote:
                          >Geoff Cox wrote:
                          >On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
                          ><paul.lautman@ btinternet.comw rote:
                          >>
                          >>
                          >>>>
                          >>>echo var_dump($row['group1']) . "<br>";
                          >>>if ($row['group1'] == 1) {
                          >>>echo "yes" . "<br>";
                          >>>} else {
                          >>>echo "no" . "<br>";
                          >>>}
                          >>>>
                          >>>} else {
                          >>>echo mysql_error();
                          >>>}
                          >>>
                          >>>I asked:
                          >>>Please post the output from
                          >>>var_dump($ro w)
                          >>>
                          >>>you posted something else.
                          >>>
                          >>>Let me try this again:
                          >>>Please post the output from
                          >>>var_dump($ro w)
                          >>
                          >Paul,
                          >>
                          >'sorry - kind of watch my lips stupid!
                          >>
                          >I get
                          >>
                          >bool(false)
                          >>
                          >Cheers,
                          >>
                          >Geoff
                          >
                          >You need to execute:
                          >$row = mysql_fetch_arr ay($result))
                          >var_dump($ro w)
                          >
                          >You do not use echo with var_dump
                          >
                          Paul,

                          I have found out how to get the

                          if ($row['group1'] == 1) { etc

                          to work but perhaps you can explain why!?

                          If I make the test within the while loop,

                          while ($row = mysql_fetch_arr ay($result)) {
                          ($row['group1'] == 1) { etc

                          this works.

                          Outside the loop $row['group1'] is empty (or NULL?)

                          Why is this?

                          Cheers

                          Geoff



                          Comment

                          • Captain Paralytic

                            #14
                            Re: equality and TINYINT field?

                            On 13 Aug, 08:40, Geoff Cox <g...@freeuk.no tcomwrote:
                            On Tue, 12 Aug 2008 14:44:29 +0100, "Paul Lautman"
                            >
                            >
                            >
                            >
                            >
                            <paul.laut...@b tinternet.comwr ote:
                            Geoff Cox wrote:
                            On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
                            <paul.laut...@b tinternet.comwr ote:
                            >
                            >>echo var_dump($row['group1']) . "<br>";
                            >>if ($row['group1'] == 1) {
                            >>echo "yes" . "<br>";
                            >>} else {
                            >>echo "no" . "<br>";
                            >>}
                            >
                            >>} else {
                            >>echo mysql_error();
                            >>}
                            >
                            >>I asked:
                            >>Please post the output from
                            >>var_dump($row )
                            >
                            >>you posted something else.
                            >
                            >>Let me try this again:
                            >>Please post the output from
                            >>var_dump($row )
                            >
                            Paul,
                            >
                            'sorry - kind of watch my lips stupid!
                            >
                            I get
                            >
                            bool(false)
                            >
                            Cheers,
                            >
                            Geoff
                            >
                            You need to execute:
                            $row = mysql_fetch_arr ay($result))
                            var_dump($row)
                            >
                            You do not use echo with var_dump
                            >
                            Paul,
                            >
                            I have found out how to get the
                            >
                            if ($row['group1'] == 1) { etc
                            >
                            to work but perhaps you can explain why!?
                            >
                            If I make the test within the while loop,
                            >
                            while ($row = mysql_fetch_arr ay($result)) {
                            ($row['group1'] == 1) { etc
                            >
                            this works.
                            >
                            Outside the loop $row['group1'] is empty (or NULL?)
                            >
                            Why is this?
                            >
                            Cheers
                            >
                            Geoff- Hide quoted text -
                            >
                            - Show quoted text -
                            $row doesn't get a value until you assign one.
                            So if you do:
                            $row = mysql_fetch_arr ay($result))
                            echo "@{$row['group1']}@"

                            Comment

                            • Geoff Berrow

                              #15
                              Re: equality and TINYINT field?

                              Message-ID: <fo35a4hg59mhcn 5lois3ohsgga3g1 jnone@4ax.comfr om Geoff Cox
                              contained the following:
                              >
                              >while ($row = mysql_fetch_arr ay($result)) {
                              >($row['group1'] == 1) { etc
                              >
                              >this works.
                              >
                              >Outside the loop $row['group1'] is empty (or NULL?)
                              >
                              >Why is this?
                              <fx: smacks head>
                              For every iteration of $row = mysql_fetch_arr ay($result) then
                              $row['group1'] will have a different value corresponding to the entry in
                              the database for that particular row. Outside the loop (below the while
                              loop in the code) $row['group1'] will have the value corresponding to
                              the last row of the database query.

                              --
                              Geoff Berrow 011000100110110 0010000000110
                              001101101011011 001000110111101 100111001011
                              100110001101101 111001011100111 010101101011
                              The Slippery Hill Boys Tel: 07985 425932. American themed barn dances and bluegrass performances. Stoke on Trent, Newcastle under Lyme, Staffordshire, Cheshire and surrounding areas.

                              Comment

                              Working...