2014-10-03 61 views
0

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

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

?> 
+3

如果像这样if(condetioion == value)不是单个的那么使用双等于 – 2014-10-03 08:08:44

+0

@ Arif_suhail_123说了什么,如果你不这样做,你没有得到一个值,而是你以某种方式设置一个一个if语句。 – Azrael 2014-10-03 08:09:31

+0

@ Arif_suhail_123我会后,作为一个答案 – 2014-10-03 08:09:36

回答

2

使用中,如果条件的双重相等。

像这样:

if(condition==value)

1

在PHP(和其他语言)有分配条件之间的差异。当你分配的东西,你用一等于,就像这样:

$something = 'value'; 

当你检查看看是否有等于什么东西,有一个条件,你使用两个等号,就像这样:

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

有同样是第三条道路,这是一个强烈的情况下,使用三个等号,这也使得确保检查:

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

而且,不e通常使用&&而不是and。不同的是&&具有更高的优先级。这在许多情况下都无关紧要,但是当您试图了解其他人的代码并与其他人一起开展项目时,您会发现它更容易。