條件的條件只是指可變$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>');
}
}
}
?>
如果像這樣if(condetioion == value)不是單個的那麼使用雙等於 – 2014-10-03 08:08:44
@ Arif_suhail_123說了什麼,如果你不這樣做,你沒有得到一個值,而是你以某種方式設置一個一個if語句。 – Azrael 2014-10-03 08:09:31
@ Arif_suhail_123我會後,作爲一個答案 – 2014-10-03 08:09:36