ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Why am I getting a ">=" syntax error?

January 31, 2012 9:27am

Subscribe [2]
  • #1 / Jan 31, 2012 9:27am

    I’ve got some conditions set up in an EE ‘if’ statement, which include some PHP variables for numeric values.

    {offer_departure format="%Y%m%d"} < "<?php echo $_SESSION['filter_from']; ?>" && {expiration_date format="%Y%m%d"} >= "<?php echo $_SESSION['filter_to']; ?>" ||
    
    {offer_departure format="%Y%m%d"} < "<?php echo $_SESSION['filter_from']; ?>" && {expiration_date format="%Y%m%d"} < "<?php echo $_SESSION['filter_to']; ?>" && {expiration_date format="%Y%m%d"} > "<?php echo $_SESSION['filter_from']; ?>" ||
    
    {offer_departure format="%Y%m%d"} >= "<?php echo $_SESSION['filter_from']; ?>" && {expiration_date format="%Y%m%d"} >= "<?php echo $_SESSION['filter_to']; ?>" && {offer_departure format="%Y%m%d"} < "<?php echo $_SESSION['filter_to']; ?>" ||
    
    {offer_departure format="%Y%m%d"} >= "<?php echo $_SESSION['filter_from']; ?>" && {expiration_date format="%Y%m%d"} < "<?php echo $_SESSION['filter_to']; ?>"


    But they are giving a syntax error when running;

    Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL in /home/sites/thecruisehub.co.uk/public_html/brain/expressionengine/libraries/Functions.php(656) : eval()‘d code on line 82


    I have set the PHP Parse for the template to Input.
    The ‘filter_from’ and ‘filter_to’ variables are numeric values rather than strings.

    Am I missing something obvious?

  • #2 / Jan 31, 2012 9:40am

    mark186282

    290 posts

    I would suspect that one of your EE variables that is being compared is not returning a result - so the rendering engine is seeing something like:

    (value from session_filter_from) && (nothing being printed here) >= (value from session_filter_to)

    so if the values would be “seen” by EE like this:

    1234 && >= 7890

    would give you the above syntax error.

    outside of the IF statement, can you print the {expiration_date format="%Y%m%d"} value to the screen to see that it is being parsed properly?  one way to do this is to simply remove the curly braces from your IF->THEN statement to “see what EE is seeing” after the parsing… (well, kinda)

  • #3 / Jan 31, 2012 12:04pm

    Problem fixed/resolved - but problem found with EE/PHP.

    In my IF loop, some conditions refer to the Expiration Date.
    However, some of the Entries I was searching, don’t have Expiration Dates, so the code throws up an error (as described above).
    I’ve bypassed the problem, by adding Expiration Dates into the searched Entries, and it all runs fine.

    This means, that EE (or is it the PHP parser?) runs through EVERY condition beforehand to make sure there are values in place for all the variables.
    eg. if (x > y) && (z <= a)

    However, if I’m wanting to use the Expiration Date as part of my conditions, and it doesn’t exist, I don’t know how to “pre-warn” the PHP that there will be no value (as the Template’s PHP is set to Input).

    Short of going through ALL the Entries and adding Expiration Dates, is there a way to get around this?

  • #4 / Jan 31, 2012 12:21pm

    mark186282

    290 posts

    hmm… 

    what about something like:

    {if expiration_date == ''}   // or whatever the "default" no expiration date value is…? 0000-00-00?
    
    /// this is the code to run if you do NOT have an expiration date to work with
    
    {if:else}
    
    /// this is the code to run if you do have an expiration date
    
    {/if}

    it may seem a bit bulky… but only half the code will run on each query loop.

  • #5 / Jan 31, 2012 1:03pm

    No I can’t do that, because the PHP is being parsed before the EE tags.
    Unless there is a way for the Expiration Date to be extracted by PHP?

  • #6 / Feb 01, 2012 2:29pm

    Kevin Smith

    4784 posts

    IC360, I understand the predicament you’re in here, but I’m not sure there’s a way around it by using PHP in the templates. Ultimately, PHP should only be used in templates when you need to do one or two tiny things that tags can’t accomplish, but we always recommend writing a plugin or module instead as a matter of best practice. In your case, it looks like it’s actually going to be necessary to write a plugin or module. In fact, you may even find it a simpler avenue than trying to bend parse order to your will. Since add-ons are written in CodeIgniter/PHP, it will be much less of a mind-bending experience than going down this track.

    Could I suggest looking into the development documentation? If you have questions during development, the Development and Programming forum is a helpful resource.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases