Solved

Why i cannot use if and else here?

Posted on 2008-06-09
6
183 Views
Last Modified: 2008-06-09
PHP
i wonder how i can use if and else statement in the code below
if i use if-else in code below i received an error message


$data1 = $data1 = "$datas | {$this->arrayAddressReturn_value[$i]} | $this->GetFileNameReturn"


if ($StudentPull == 0)  {//get file from config.php
switch($this->GetstudentID[$i])  //to get student id from other function
{
  case 1: $fn = $file1; break;
  case 2: $fn = $file2; break;
}

file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
}
}

else
{
foreach($this->GetFileNameReturn as $FileName) //get file from database
      {
 switch($this->GetstudentID[$i])
{
  case 1: $fn = $FileName; break;
  case 2: $fn = $FileName; break;
  case 3: $fn = $FileName; break;
// default:$fn = UNKNOWN; break;
}

file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
      }
}
}
0
Comment
Question by:firekiller15
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:JesterToo
ID: 21747984
You have an extra "}" at line 12/13
0
 

Author Comment

by:firekiller15
ID: 21748127
how about this
i received this error
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\test.php on line 531
foreach($array as $i=> $datas)
{
$data1 = "$datas | {$this->arrayaddressReturn_value[$i]} | 
 
if ($UniversePull)  
 {
switch($this->GetUniverseID[$i])
  {
 case 1: $fn = $file1; break;
 case 2: $fn = $file2; break;
 case 3: $fn = $file3; break;
 default:$fn = $file4; break;
  }
 
file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
 }
 
else
 {
foreach($this->GetFileNameReturn as $FileName)
  {
 switch($this->GetUniverseID[$i])
   {
  case 1: $fn = $FileName; break;
  case 2: $fn = $FileName; break;
  case 3: $fn = $FileName; break;
   }
 
file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
  }
 }
}

Open in new window

0
 
LVL 16

Accepted Solution

by:
DrNikon224 earned 250 total points
ID: 21748149
There are double-quotes opened on line 3, but never closed. I think you're missing the tail end of line 3.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:firekiller15
ID: 21748157
that one is typo
ok fix but still have that error message
0
 

Author Comment

by:firekiller15
ID: 21748165
if i get rid of else then no error
why cannot put else here
0
 
LVL 16

Expert Comment

by:DrNikon224
ID: 21748169
Which line of the code you posted is the line 531 referenced in the error? Can you post your typo-fixed code, marked with a comment at line 531?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 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