?
Solved

php,if statements embedded inside switch

Posted on 2008-10-13
8
Medium Priority
?
1,286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

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 i…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …
Suggested Courses

762 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