Solved

php,if statements embedded inside switch

Posted on 2008-10-13
8
1,270 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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 …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 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

20 Experts available now in Live!

Get 1:1 Help Now