2014-10-03 47 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。不同的是&&具有更高的優先級。這在許多情況下都無關緊要,但是當您試圖瞭解其他人的代碼並與其他人一起開展項目時,您會發現它更容易。