2013-07-22 164 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

相關問題