Solved

Syntax on if statement

Posted on 2014-07-23
6
98 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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 110

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 110

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

Suggested Solutions

Title # Comments Views Activity
Code not executing correctly. 3 41
Format Date 7 23
Load string Array from file 23 36
php non-object 7 21
This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
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.

740 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