我是PhP和MySQL的新手,現在無法顯示某些記錄。我有記錄學生的列表和他們的年級存儲在數據庫中。我能夠在網頁中顯示所有這些內容。現在我有一個文本框和一個按鈕,我想要做的是當我在文本框中輸入例如「1」並單擊按鈕時,我的頁面上顯示的內容將僅爲所有第一年級學生的記錄。如何回發到數據庫?
不知怎的,我需要改變它,這樣當年份被髮回時,它會更改sql以限制顯示的信息。
任何建議或指向一些例子的鏈接將不勝感激。這是我的代碼。
<form name="form1" method="post" action="">
<div align="center">
<?php
include("dbcon.php");
$query="select * from student order by year, studname";
[email protected]_query($query) or die(mysql_error());
if(mysql_num_rows($result)>0)
{
?>
<label>
<input type="text" name="txtyear" id="txtyear">
<input type="submit" name="btnyear" id="btnyear" value="Submit">
</label>
<table width="75%" border="1">
<tr>
<td align="center" width="20%"><strong>Student Number</strong></td>
<td align="center" width="27%"><strong>Name</strong></td>
<td align="center" width="23%"><strong>Course</strong></td>
<td align="center" width="30%"><strong>Year Level</strong></td>
</tr>
<?php
while($row=mysql_fetch_array($result))
{echo "<tr>";
echo "<td>".$row['studno']."</td>";
echo "<td>".$row['studname']."</td>";
echo "<td>".$row['course']."</td>";
echo "<td>".$row['year']."</td>";
echo "</tr>";
}
?>
</table>
<?php
}
else
echo "no records found";
?>
</div>
</form>
使用'LIMIT':'select * from student order by year,studname LIMIT x OFFSET y' –