未读取PHP条件


PHP condition not being read

条件没有被读取条件只是指变量$year$sem的值似乎第一个条件只是被读取的条件如果$year='4th'$sem='1st'显示的是第一个条件的输出,即$year='1st'$sem='1st'我哪里错了?请帮忙提前感谢这是我的代码

<?php
session_start();
$username=$_SESSION['username'];
echo $username ;
$year=$_SESSION['year'];
echo $year;
$sem=$_SESSION['sem'];
echo $sem;
$course=$_SESSION['course'];
$con=mysql_connect('server','username','password');
mysql_select_db($course );
echo $course;
if($year='1st' and $sem='1st')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 1st_year_1st_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 1st_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 1st_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='1st' and $sem='2nd')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 1st_year_2nd_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 1st_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 1st_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='2nd' and $sem='1st')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 2nd_year_1st_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 2nd_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 2nd_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='2nd' and $sem='2nd')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 2nd_year_2nd_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 2nd_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 2nd_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='3rd' and $sem='1st')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 3rd_year_1st_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 3rd_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 3rd_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='3rd' and $sem='2nd')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 3rd_year_2nd_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 3rd_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 3rd_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='4th' and $sem='1st')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 4th_year_1st_sem WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 4th_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 4th_year_1st_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
elseif($year='4th' and $sem='2nd')
{
    echo('
    <center>
    <table border=1>
    <tr>
    <th bgcolor=pink>STUDENT NAME</th>
    ');
    $a=mysql_query("SHOW FIELDS FROM 4th_year_2nd_sem like WHERE Field NOT IN ('USERNAME', 'STUDENTNUMBER', 'STUDENTNAME', 'SUBJECTS', 'UNITS')") OR DIE(MYSQL_ERROR());
    while($b=mysql_fetch_array($a))
    {
    echo ('<th bgcolor=pink>'.$b[0].'</th>');
    }
    echo('</tr>');
    $aaa=mysql_query("select STUDENTNAME FROM 4th_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
    while($bbb=mysql_fetch_array($aaa))
    {
    echo ('<td width=200 bgcolor=orange><input type=text value="'.$bbb[0].'" style="width:100%" readonly></td>');
    }
    $aa=mysql_query("SELECT * FROM 4th_year_2nd_sem WHERE USERNAME='$username'") OR DIE(MYSQL_ERROR());
        while($bb=mysql_fetch_array($aa, MYSQL_NUM))
    {
        for ($count=5; $count < count($bb); $count++)
        {
        echo ('<td align=center width=80 bgcolor=lightblue><input type=text value="'.$bb[$count].'" style="width:100%; text-align:center" readonly></td>');
        }
    }
}
?>

在if条件中使用双等号。

像这样:

if(condition==value)

在PHP(和其他语言)中,赋值条件之间存在差异。当你分配一些东西时,你使用一个等于,就像这样:

$something = 'value';

当你检查某个东西是否等于某个东西时,在有条件的情况下,你会使用两个相等的值,就像这样:

if ($something == 'value') { ...

还有第三种方法,这是一个强条件,使用三个相等,这也确保检查类型

if ($myInteger === "13") { // always false, as "13" is a string!

此外,请注意,使用&&而不是and更为常见。不同之处在于&&具有更高的优先级。在很多情况下,这并不重要,但当你试图理解他人的代码并与他人一起处理项目时,你可能会发现这更容易。