这样的事情有可能吗?

时间:2013-07-22 15:54:22

标签: php if-statement

<?php
$division=$row['mark'];
$pass="Passed";
if($division>=80 && $pass==include "result.php")// Result.php has two value: one is `Pass` and the other is `Fail`.
{
  echo "Letter";
}
elseif($division>=70 && $pass==include "result.php")
{
  echo "First";
}
else
{
  echo "Fail";
}
?>

我想在此输出的内容是:如果$division等于80且同时$pass等于Passed,则回显Letter。但如果$division小于70,则回显Fail;此处$pass此处等于fail,该result.php取自FailFailFailFail。我一直在尝试使用以下代码输出它,但它不起作用。当$division小于70时,它会输出<?php $eng=40; $mizo=40; $hindi=40; $maths=40; $ss=40; $science=40; if ($eng>=40 && $mizo>=40 && $hindi>=40 && $maths>=40 && $ss>=40 && $science>=40) { echo "<font color=green>Passed</font>"; } else { echo "<font color=red>Failed</font>"; } ?>

Result.php的代码

{{1}}

3 个答案:

答案 0 :(得分:1)

你正在以错误的方式解决这个问题。你无法比较像这样的包含的结果,更不用说它们无法正确匹配,因为你要将单个单词字符串与一个包含大量HTML的字符串进行比较。

更好的方法是包含results.php并将答案存储在变量中。我在下面写了一个例子。

首先,您需要将result.php更改为:

<?php
$eng=40;
$mizo=40;
$hindi=40;
$maths=40;
$ss=40;
$science=40;

if ($eng>=40 && $mizo>=40 && $hindi>=40 && $maths>=40 && $ss>=40 && $science>=40)
{
    $test = "Passed";
}
else 
{
    $test = "Failed";
}
?>

然后将以下内容放在第一个文件中:

<?php
$division=$row['mark'];
$pass="Passed";
include("result.php");// Result.php has two value: one is `Pass` and the other is `Fail`, store in $test.
if($division>=80 && $pass==$test)
{
  echo "Letter";
}
elseif($division>=70 && $pass==$test)
{
  echo "First";
}
else
{
  echo "Fail";
}
?>

答案 1 :(得分:0)

您需要先包含该文件:

<?php

include "result.php"; //include the file

$division =$ row['mark'];
$pass = "Passed";

if($division == 80 && $pass == "Passed") {
  echo "Letter";
}

elseif($division < 70) {
  echo "Fail";
}

?>

答案 2 :(得分:0)

这样的事情会做。对于result.php,请使用以下命令:

 <?php
 $eng= 40;
 $mizo= 40; 
 $hindi= 40; 
 $maths= 40; 
 $ss= 40; 
 $science= 40; 

//  first group your variable into one array = $all
$all = array($eng, $mizo, $hindi, $maths, $ss, $science); 
// second, just iterate over them till you find one value -40
for($i=0; $i < count($all); $i++){
if($all[$i] < 40) $sum = 1;
}
?>

输出:

<?php include "result.php";?>
<?php 
$division=$row_['mark'];
$pass="Passed";
$test = (!empty($sum)) ? 'Failed' : 'Passed';
if($division>=80 && $pass==$test)
{
echo "Letter";
}
elseif($division>=70 && $pass==$test)
{
echo "First"; 
}
else
{
echo "Passed";
}
?>