Solved

Syntax on if statement

Posted on 2014-07-23
6
82 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 82

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 108

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 108

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 16

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 108

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP loop not working 4 33
Google maps, choose location using pin 10 23
Wordpress Body Class 5 15
How to fetch your row in php 14 13
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now