[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1300
  • Last Modified:

php,if statements embedded inside switch

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
Erikal
Asked:
Erikal
1 Solution
 
wellsoCommented:
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
 
ErikalAuthor Commented:
OK
I tried it. I get exatly the same error for the same line.
0
 
butterhookCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
markloganCommented:
Check your brackets around the IF statement.
0
 
markloganCommented:
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
 
markloganCommented:
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
 
ErikalAuthor Commented:
Thanks very much marklogan:
It was the brackets in the if statements after all.
Problem sorted.
0
 
Beverley PortlockCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now