Solved

php,if statements embedded inside switch

Posted on 2008-10-13
8
1,273 Views
Last Modified: 2013-12-13
Hello,
This is a follow on prom my previous question.
I have attempted to embed two levels of if statements in each case of a switch statement.
I get the following parse error:
Parse error: parse error, unexpected '{' in /share/storage/03/ny/nyorulmaz/PFeedback1.php on line 298
First of all, I am not sure if this is allowed.
If yes, could some please see what has gone wrong. I have again marked the offending line.
Here is the relevantpart of the code:
=======================================
if ($Score1<90 && $Score1>=85)
{
    switch ($weeks){
        case ($weeks <= 10):
        echo " some text goes here"; //...........................offending line 298 starts here....................
if (round(($comp1mark*100/count($comp1))<75 || round(($spell1mark*100/count($spell1))<75 || round(($engmark1['punc_mark']*100/10)<75)
echo "English: <BR>";
{
      if (round(($comp1mark*100/count($comp1))<75)
      echo "................some text goes here....................";
      if (round(($spell1mark*100/count($spell1))<75)
      echo "................some text goes here....................";
      if (round(($engmark1['punc_mark']*100/10)<75)
      echo "................some text goes here....................";
}
if (round(($arith1mark*100/count($arith1))<75 || round(($pdf1mark*100/count($pdf1))<75 || round(($arper1mark*100/count($arper1))<75 || round(($totav1mark*100/count($totav1))<75 || round(($pie1mark*100/count($pie1))<75)
echo "Maths: <BR>";
{
      if (round(($arith1mark*100/count($arith1))<75)
      echo "................some text goes here....................";
      if (round(($pdf1mark*100/count($pdf1))<75)
      echo "................some text goes here....................";
      if (round(($arper1mark*100/count($arper1))<75)
      echo "................some text goes here....................";
      if (round(($totav1mark*100/count($totav1))<75)
      echo "................some text goes here....................";
      if (round(($pie1mark*100/count($pie1))<75)
      echo "................some text goes here....................";
}
if (round(($wordrel1mark*100/count($wordrel1))<75 || round(($numser1mark*100/count($numser1))<75 || round(($misslets1mark*100/count($misslets1))<75 || round (($letrel1mark*100/count($letrel1))<75 || round(($sercode1mark*100/count($sercode1))<75)
echo "Maths: <BR>";
{            
      if (round(($wordrel1mark*100/count($wordrel1))<75)
      echo "................some text goes here....................";
      if (round(($numser1mark*100/count($numser1))<75)
      echo "................some text goes here....................";
      if (round(($misslets1mark*100/count($misslets1))<75)
      echo "................some text goes here....................";
      if (round(($letrel1mark*100/count($letrel1))<75)
      echo "................some text goes here....................";
      if (round(($sercode1mark*100/count($sercode1))<75)
      echo "................some text goes here....................";
}
        break;

        case ($weeks >10 AND $weeks <= 20):
echo "................some text goes here....................";
        break;
                   
        case ($weeks >20 AND $weeks <= 40):
echo "................some text goes here....................";
        break;
                               
       case ($weeks >= 40):
echo "................some text goes here....................";

        break;
    }
}
0
Comment
Question by:Erikal
8 Comments
 
LVL 2

Expert Comment

by:wellso
ID: 22701140
I thin it might be because you are executing more than one line of code after the IF statement. I have changed the code a bit below, all I have done is added braces to the larger if statements
if ($Score1<90 && $Score1>=85)

{

    switch ($weeks){

        case ($weeks <= 10):

        echo " some text goes here";

if (round(($comp1mark*100/count($comp1))<75 || round(($spell1mark*100/count($spell1))<75 || round(($engmark1['punc_mark']*100/10)<75){

echo "English: <BR>";

      if (round(($comp1mark*100/count($comp1))<75)

      echo "................some text goes here....................";

      if (round(($spell1mark*100/count($spell1))<75)

      echo "................some text goes here....................";

      if (round(($engmark1['punc_mark']*100/10)<75)

      echo "................some text goes here....................";

}

if (round(($arith1mark*100/count($arith1))<75 || round(($pdf1mark*100/count($pdf1))<75 || round(($arper1mark*100/count($arper1))<75 || round(($totav1mark*100/count($totav1))<75 || round(($pie1mark*100/count($pie1))<75)

{

echo "Maths: <BR>";
 

      if (round(($arith1mark*100/count($arith1))<75)

      echo "................some text goes here....................";

      if (round(($pdf1mark*100/count($pdf1))<75)

      echo "................some text goes here....................";

      if (round(($arper1mark*100/count($arper1))<75)

      echo "................some text goes here....................";

      if (round(($totav1mark*100/count($totav1))<75)

      echo "................some text goes here....................";

      if (round(($pie1mark*100/count($pie1))<75)

      echo "................some text goes here....................";

}

if (round(($wordrel1mark*100/count($wordrel1))<75 || round(($numser1mark*100/count($numser1))<75 || round(($misslets1mark*100/count($misslets1))<75 || round (($letrel1mark*100/count($letrel1))<75 || round(($sercode1mark*100/count($sercode1))<75)

{

echo "Maths: <BR>";

            

      if (round(($wordrel1mark*100/count($wordrel1))<75)

      echo "................some text goes here....................";

      if (round(($numser1mark*100/count($numser1))<75)

      echo "................some text goes here....................";

      if (round(($misslets1mark*100/count($misslets1))<75)

      echo "................some text goes here....................";

      if (round(($letrel1mark*100/count($letrel1))<75)

      echo "................some text goes here....................";

      if (round(($sercode1mark*100/count($sercode1))<75)

      echo "................some text goes here....................";

}

        break;
 

        case ($weeks >10 AND $weeks <= 20):

echo "................some text goes here....................";

        break;

                   

        case ($weeks >20 AND $weeks <= 40):

echo "................some text goes here....................";

        break;

                               

       case ($weeks >= 40):

echo "................some text goes here....................";
 

        break;

    }

}

Open in new window

0
 

Author Comment

by:Erikal
ID: 22701199
OK
I tried it. I get exatly the same error for the same line.
0
 
LVL 1

Expert Comment

by:butterhook
ID: 22701356
I think it's because you echo "English: etc....

Before you open the { after the first if?

This should be after, as in the second block below


if (round(($comp1mark*100/count($comp1))<75 || round(($spell1mark*100/count($spell1))<75 || round(($engmark1['punc_mark']*100/10)<75)

echo "English: <BR>";

{
 

// ----------------------- 

if (round(($comp1mark*100/count($comp1))<75 || round(($spell1mark*100/count($spell1))<75 || round(($engmark1['punc_mark']*100/10)<75)
 

{
 

echo "English: <BR>";

Open in new window

0
 
LVL 7

Expert Comment

by:marklogan
ID: 22701414
Check your brackets around the IF statement.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:marklogan
ID: 22701419
Forgot the tick box.
if (round(($comp1mark*100/count($comp1))<75)) || round(($spell1mark*100/count($spell1))<75) || round(($engmark1['punc_mark']*100/10)<75)

Open in new window

0
 
LVL 7

Accepted Solution

by:
marklogan earned 500 total points
ID: 22701431
It also depends on your formatting style. How you like your IF statements
if ((round($comp1mark*100/count($comp1))<75) || (round($spell1mark*100/count($spell1))<75) || (round($engmark1['punc_mark']*100/10)<75)){

Open in new window

0
 

Author Closing Comment

by:Erikal
ID: 31505556
Thanks very much marklogan:
It was the brackets in the if statements after all.
Problem sorted.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 22701731
Case statements can only evaluate to a simple number type like  1, 2 3, 4, etc. Your expressions will evaluate to 1 or zero as they represent true false.

See http://uk3.php.net/switch
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

912 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

16 Experts available now in Live!

Get 1:1 Help Now