Php 这样的事情有可能吗?

Php 这样的事情有可能吗?,php,if-statement,Php,If Statement,你这样做完全是错误的。您无法比较这样一个include的结果,更不用说它们无论如何都不匹配,因为您将一个单词字符串与一个包含大量HTML的字符串进行比较 更好的方法是包含results.php并将答案存储在变量中。我在下面写了一个例子 首先,您需要将result.php更改为: <?php $eng=40; $mizo=40; $hindi=40; $maths=40; $ss=40; $science=40; if ($eng>=40 &

你这样做完全是错误的。您无法比较这样一个include的结果,更不用说它们无论如何都不匹配,因为您将一个单词字符串与一个包含大量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)
   {
   echo "<font color=green>Passed</font>";
   }
   else 
   {
   echo "<font color=red>Failed</font>";
   }
   ?>
<?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
   $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>";
   }
   ?>
<?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";
}
?>

像这样的东西就可以了。对于result.php,请使用以下命令:

<?php

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

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

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

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

?>

对于输出:

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


为什么不将
$pass=include“result.php”
移到if语句上方?在描述中没有提到“First”。有必要吗?显示result.phpResult.php的代码是什么样子的。您能否在页面顶部只包含一次,然后使用result.php中的函数返回say$return变量中的值,然后对其执行条件检查?呃,当$division小于70时,为什么不应该说fail?这就是您编写代码的方式。只有除法为70或更大时,它才会输出字母/first,否则它应该说fail。$Styphon我将测试您的脚本并让您知道它是如何产生的。谢谢,还是有问题。它同时回显
第一次
失败
。你调试代码了吗?当除法大于70且小于80时,预期输出仅为
First
,而不是
First
Failed
,就像您的代码输出一样。可能有一些技巧。它不能同时输出这两个,这是一个if语句。只要一个人输出,那就是语句的结尾。你肯定在别处重复了。我刚刚重新检查了你的代码,看看它是否也能正常工作。我的问题是我在
result.php中使用了
,而没有使用
$pass='Passed'
中的标记。谢谢你的大力帮助。我想你误解了他想要实现的目标。他想用$pass测试result.php的输出。你怎么能想出这么好的解决方案呢。它又漂亮又短,能妥善处理我想要的一切。非常感谢。