PHP条件未被读取

时间:2014-10-03 08:07:39

标签: php

条件未被读取条件只是引用变量$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>');
        }
    }
}

?>

2 个答案:

答案 0 :(得分:2)

在if条件中使用double equal。

像这样:

if(condition==value)

答案 1 :(得分:1)

在PHP(和其他语言)中,分配条件之间存在差异。分配内容时,使用一个等号,如下所示:

$something = 'value';

当你检查某件事情是否等于某件事情时,你会使用两个等号,如下:

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

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

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

另请注意,使用&&代替and更为常见。不同之处在于&&具有更高的优先级。这在很多情况下都很重要,但在尝试了解其他人的代码并与其他人一起开展项目时,您可能会觉得更容易。