Solved

Syntax on if statement

Posted on 2014-07-23
6
91 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error log using ftp 7 41
PHP AJAX JSON 2 61
comma true 6 34
PHP error function not working on AWS 10 11
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

831 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