Solved

php,if statements embedded inside switch

Posted on 2008-10-13
8
1,275 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 7

Expert Comment

by:marklogan
ID: 22701414
Check your brackets around the IF statement.
0
 
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

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 look for a specific file type in a local or remote server directory using PHP.

777 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