Solved

Syntax on if statement

Posted on 2014-07-23
6
94 Views
Last Modified: 2014-08-13
What is wrong with the line that has $ROW[NOR]
I know it's syntax.

if ("$Up_Down" == "U")
                        (
                        if ("{$ROW['NOR']}" > $North_Grid)
                              {
                                    continue;
                              }
0
Comment
Question by:breeze351
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40215179
When you put quotes around the variables, they become text and not variables.  Try this...
if ($Up_Down == "U")
                        (
                        if ($ROW['NOR'] > $North_Grid)
                              {
                                    continue;
                              } 

Open in new window

And is it 'ROW' or 'row'?  Remember that PHP variable names are case sensitive.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40215457
PHP variable names are case sensitive.
And so are array indexes in associative arrays.  And so are property names in objects.

This article tells how to use quote marks in PHP.  Executive summary: Fewer quote marks are almost always better.  If you still have any questions after reading the article, please post back and we'll be glad to clarify.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40215467
And now that I look at the code in my text editor I see that the character on line 2 is an open-paren, not a curly brace.  Curly braces are used for control structures in PHP.  Try it a bit more like this (at least this will parse correctly).  In this code snippet, line #5 is the same as line 2 in the original question.  ( != {

<?php // demo/temp_breeze351.php
error_reporting(E_ALL);

if ("$Up_Down" == "U")
{
    if ($ROW['NOR'] > $North_Grid)
    {
        continue;
    } 
}

Open in new window

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 17

Accepted Solution

by:
Chris Harte earned 500 total points
ID: 40216337
Strange looking code. Braces inside double quotes stops the variable being parsed. If that is what you want, and I cannot imagine why it would be,  then this may be the correct code. As Ray mentioned, parenthesis are not braces

if ($Up_Down == "U")
{
    if ('$ROW["NOR"]' > $North_Grid)
    {
        continue;
    }
}

Open in new window

0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 40219033
Hi,

I have tried the below code based on my local box, it is working fine,

$ROW['NOR'] = 12;
$North_Grid = 10;
$Up_Down = 'U';

if ("$Up_Down" == "U"){
if ("{$ROW['NOR']}" > $North_Grid) {
                  echo 'Test';
        }
}
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40219198
@vimalmaria: Yes, the parse error is caused by using parenthesis instead of curly braces.  PHP often reports these kinds of parse errors on the line that triggered the error in the parser, which may not be the same line number as the line that contained the wrong character.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question