2013-07-22 166 views
-3
<?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有什么办法可以这样吗?

代码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) 
    { 
    echo "<font color=green>Passed</font>"; 
    } 
    else 
    { 
    echo "<font color=red>Failed</font>"; 
    } 
    ?> 
+0

你为什么不动'$通=包括上面的if语句 “result.php”'? –

+0

在你的描述中,你不会说“第一”。有必要吗? – user4035

+0

显示result.php中的内容 – Orangepill

回答

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"; 
} 
?> 
+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"; 
} 
?> 
+0

$ Styphon我会测试你的脚本,并让你知道它是怎么来的。谢谢。 –

+0

你以前的代码工作正常。谢谢。 –

+0

还是有一些问题。它回应了“First”和“Failed”。你有没有调试过你的代码?当Division大于70且小于80时,当您的代码输出时,预期输出仅为“First”,而不是“First”和“Failed”。可能有一些技巧。 –

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"; 
} 

?> 
+1

我想你已经错过了他想要完成的事情。他想测试result.php的输出与$ pass中的内容。 – Styphon

相关问题