This makes no sense to me, simple comparisons.

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

    This makes no sense to me, simple comparisons.


    I'm attempting to trigger things based on time.
    I have one shop that has opening hours, closing hours and lunch hours store
    as full hour values, integer, in MySQL.
    I retrieve them, based on comparisons either shop is open, about to close or
    actually closed.
    When open, nothing particular is written, when closed, customer is informed
    orders can't be executed, shop is closed.
    But the last one, right about 15 minutes before closing time, should trigger
    a special message to customers, but that comparison just won't work.

    [code]
    This is what I got:
    $closeManTor = (int) $row["closeManTo r"];
    $timer = (int) date("H");
    $minutter = (int) date("i");

    and in a switch statement:
    if(($closeManTo r-1) == $timer && $minutter >= 45)
    return $almost_closed;
    [code]

    I tried to modify the last comparing statement to a simpler way,

    if($closeManTor == $timer && $minutter >= 0)
    return $almost_closed;

    but even this fails.

    I know for sure that I do compare integers, all have been checked using
    gettype(), but that simple if statement just won't trigger anything.
    Yes, I have assigned a value to $almost_closed, no problem there.

    The switch works fine, as I have another if sentence in the same triggered
    statement that works just fine. Connecting these two if-statements with an
    if-else-if structure, didn't change anything at all, that's why the first
    statement isn't shown here.

    I really am getting grey hair here, rather, more then I do have ... and I'm
    too young to get all grey haired already now ;-)

    I'm sorry, but I really don't understand this one here.

    /Andreas

    --
    Registeret Linux user #292411
  • Pedro Graca

    #2
    Re: This makes no sense to me, simple comparisons.

    Andreas Paasch wrote:[color=blue]
    > I'm attempting to trigger things based on time.
    > I have one shop that has opening hours, closing hours and lunch hours store
    > as full hour values, integer, in MySQL.
    > I retrieve them, based on comparisons either shop is open, about to close or
    > actually closed.
    > When open, nothing particular is written, when closed, customer is informed
    > orders can't be executed, shop is closed.
    > But the last one, right about 15 minutes before closing time, should trigger
    > a special message to customers, but that comparison just won't work.
    >
    > [code]
    > This is what I got:
    > $closeManTor = (int) $row["closeManTo r"];
    > $timer = (int) date("H");
    > $minutter = (int) date("i");
    >
    > and in a switch statement:
    > if(($closeManTo r-1) == $timer && $minutter >= 45)
    > return $almost_closed;
    > [code]
    >
    > I tried to modify the last comparing statement to a simpler way,
    >
    > if($closeManTor == $timer && $minutter >= 0)
    > return $almost_closed;
    >
    > but even this fails.[/color]

    Does your code behave the same way with constants?
    [code]
    /* ! */ ## changed lines
    /* ! */ $closeManTor = 12;
    /* ! */ $timer = 11;
    /* ! */ $minutter = 53;
    [code]
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Andreas Paasch

      #3
      Re: This makes no sense to me, simple comparisons.

      Pedro Graca wrote:
      [color=blue]
      > Andreas Paasch wrote:[color=green]
      >> I'm attempting to trigger things based on time.
      >> I have one shop that has opening hours, closing hours and lunch hours
      >> store as full hour values, integer, in MySQL.
      >> I retrieve them, based on comparisons either shop is open, about to close
      >> or actually closed.
      >> When open, nothing particular is written, when closed, customer is
      >> informed orders can't be executed, shop is closed.
      >> But the last one, right about 15 minutes before closing time, should
      >> trigger a special message to customers, but that comparison just won't
      >> work.
      >>
      >> [code]
      >> This is what I got:
      >> $closeManTor = (int) $row["closeManTo r"];
      >> $timer = (int) date("H");
      >> $minutter = (int) date("i");
      >>
      >> and in a switch statement:
      >> if(($closeManTo r-1) == $timer && $minutter >= 45)
      >> return $almost_closed;
      >> [code]
      >>
      >> I tried to modify the last comparing statement to a simpler way,
      >>
      >> if($closeManTor == $timer && $minutter >= 0)
      >> return $almost_closed;
      >>
      >> but even this fails.[/color]
      >
      > Does your code behave the same way with constants?
      > [code]
      > /* ! */ ## changed lines
      > /* ! */ $closeManTor = 12;
      > /* ! */ $timer = 11;
      > /* ! */ $minutter = 53;
      > [code][/color]

      Yes, but

      I had another way to check it, and there it works fine, so the problem is
      not in this comparison itself, but actually somewhere else.

      Your hint about fixing the variables and then running it again, made me
      rethink once again and led me to another error that needs to be tracked
      down now, thanks for the hint :-)

      /Andreas

      --
      Registeret Linux user #292411

      Comment

      • Pedro Graca

        #4
        Re: This makes no sense to me, simple comparisons.

        Andreas Paasch wrote:[color=blue]
        > Yes, but
        >
        > I had another way to check it, and there it works fine, so the problem is
        > not in this comparison itself, but actually somewhere else.[/color]

        That's what I figured ...
        [color=blue]
        > Your hint about fixing the variables and then running it again, made me
        > rethink once again and led me to another error that needs to be tracked
        > down now, thanks for the hint :-)[/color]

        I never expected it to work with those constants -- though it should :)

        Happy bug hunting

        /me loves bug hunting
        --
        --= my mail box only accepts =--
        --= Content-Type: text/plain =--
        --= Size below 10001 bytes =--

        Comment

        • Jochen Daum

          #5
          Re: This makes no sense to me, simple comparisons.

          Hi Andreas!

          On Mon, 16 Feb 2004 22:49:57 +0100, Andreas Paasch
          <Andreas@Paasch .Net> wrote:
          [color=blue]
          >
          >I'm attempting to trigger things based on time.
          >I have one shop that has opening hours, closing hours and lunch hours store
          >as full hour values, integer, in MySQL.
          >I retrieve them, based on comparisons either shop is open, about to close or
          >actually closed.
          >When open, nothing particular is written, when closed, customer is informed
          >orders can't be executed, shop is closed.
          >But the last one, right about 15 minutes before closing time, should trigger
          >a special message to customers, but that comparison just won't work.
          >
          >[code]
          >This is what I got:
          > $closeManTor = (int) $row["closeManTo r"];
          >$timer = (int) date("H");
          >$minutter = (int) date("i");
          >
          >and in a switch statement:
          > if(($closeManTo r-1) == $timer && $minutter >= 45)[/color]

          try with brackets:

          if((($closeManT or-1) == $timer) && ($minutter >= 45))

          and try var_dump(($clos eManTor-1) == $timer));
          and var_dump(($minu tter >= 45));

          before.

          HTH, Jochen


          [color=blue]
          > return $almost_closed;
          >[code]
          >
          >I tried to modify the last comparing statement to a simpler way,
          >
          > if($closeManTor == $timer && $minutter >= 0)
          > return $almost_closed;
          >
          >but even this fails.
          >
          >I know for sure that I do compare integers, all have been checked using
          >gettype(), but that simple if statement just won't trigger anything.
          >Yes, I have assigned a value to $almost_closed, no problem there.
          >
          >The switch works fine, as I have another if sentence in the same triggered
          >statement that works just fine. Connecting these two if-statements with an
          >if-else-if structure, didn't change anything at all, that's why the first
          >statement isn't shown here.
          >
          >I really am getting grey hair here, rather, more then I do have ... and I'm
          >too young to get all grey haired already now ;-)
          >
          >I'm sorry, but I really don't understand this one here.
          >
          >/Andreas[/color]

          --
          Jochen Daum - Cabletalk Group Ltd.
          PHP DB Edit Toolkit -- PHP scripts for building
          database editing interfaces.
          http://sourceforge.net/projects/phpdbedittk/

          Comment

          • Dan Tripp

            #6
            Re: This makes no sense to me, simple comparisons.

            Andreas Paasch wrote:
            [color=blue]
            > Pedro Graca wrote:
            >
            >[color=green]
            >>Andreas Paasch wrote:
            >>[color=darkred]
            >>>I'm attempting to trigger things based on time.
            >>>I have one shop that has opening hours, closing hours and lunch hours
            >>>store as full hour values, integer, in MySQL.
            >>>I retrieve them, based on comparisons either shop is open, about to close
            >>>or actually closed.
            >>>When open, nothing particular is written, when closed, customer is
            >>>informed orders can't be executed, shop is closed.
            >>>But the last one, right about 15 minutes before closing time, should
            >>>trigger a special message to customers, but that comparison just won't
            >>>work.
            >>>
            >>>[code]
            >>>This is what I got:
            >>> $closeManTor = (int) $row["closeManTo r"];
            >>>$timer = (int) date("H");
            >>>$minutter = (int) date("i");
            >>>
            >>>and in a switch statement:
            >>> if(($closeManTo r-1) == $timer && $minutter >= 45)
            >>> return $almost_closed;
            >>>[code]
            >>>
            >>>I tried to modify the last comparing statement to a simpler way,
            >>>
            >>> if($closeManTor == $timer && $minutter >= 0)
            >>> return $almost_closed;
            >>>
            >>>but even this fails.[/color]
            >>
            >>Does your code behave the same way with constants?
            >>[code]
            >>/* ! */ ## changed lines
            >>/* ! */ $closeManTor = 12;
            >>/* ! */ $timer = 11;
            >>/* ! */ $minutter = 53;
            >>[code][/color]
            >
            >
            > Yes, but
            >
            > I had another way to check it, and there it works fine, so the problem is
            > not in this comparison itself, but actually somewhere else.
            >
            > Your hint about fixing the variables and then running it again, made me
            > rethink once again and led me to another error that needs to be tracked
            > down now, thanks for the hint :-)
            >
            > /Andreas
            >[/color]


            Just throwin' this out there, but if your switch statement(s)
            evaluate(s) to true, and you're got a "break:" nestled in there, you
            might be getting a false positive, and your true positive isn't being
            evaluated.

            Point being, you might want to juggle the order in which your switch
            conditions are evaluated.

            Here's kinda what I'm getting at:

            In the sample below, you won't ever see the bottom two cases, because
            the second case evaluates as a match, and breaks out of the switch
            statement.

            <?php

            $something = 1;
            $condOne = "TRUE";

            switch($somethi ng){
            case 0:
            echo "Something is nothing!";
            break;
            case 1:
            echo "Something is 1!";
            break;
            case 1 && ($condOne=="TRU E"):
            echo "Something is 1 and condOne is TRUE!";
            break;
            case 1 && ($condOne=="FAL SE"):
            echo "Something is 1 and condOne is FALSE!";
            break;
            }

            ?>

            Regards,

            - Dan
            http://blog.dantripp.c om/

            Comment

            Working...