我自告奮勇,想創造一些還挺數據庫供我上學,有效地跟蹤學生的不當行爲。我不是專家。我一直在做的是,我爲了我想要的,自學了它,並試圖將所有東西縫合在一起。PHP動態複選框列表,基於級聯選擇選擇
我碰到這個教程,差不多就是我想要的,我的工作在此基礎上對數據庫:http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/
,因此,我想出了這一點:http://ipoh.wesleyschool.edu.my/ace_beta.php
整體思路是基於選擇的班級,該特定班級的學生將作爲列表出現。
整個事情的作品的那一刻,但我想它推到另一個層次。正如你所看到的,我寫的東西只允許一個學生一次,如果我想同時選擇多個學生做同樣的錯誤行爲呢?
我Google的「動態複選框」等。但不知何故,我不知道將它們連接,使其工作...我已經試了又試,這就是爲什麼你在這裏找到我問。
CODE(ace_beta.php):
主網頁上運行:ace_beta.php;其中,我相信我卡在這個地方:
<td width="25%" valign="top"'>
<table border="0" width="100%" cellpadding="6">
<tr>
<td width="100%" align="middle" valign="top" bgcolor='#636363'>
<font face="Arial" size='5' color='#ffffff'><b> STEP ONE </b></font>
</td></tr></table>
<br />
<b> STUDENT INFORMATION ::. </b>
<br />
<table border="0" width="100%" cellpadding="3">
<tr>
<td width="20%" align="right"> class </td>
<td width="80%" align="left">
<select id="class" name="class">
<?php echo $opt->ShowClass(); ?>
</select></td>
</tr>
<tr>
<td width="20%" align="right"> student </td>
<td width="80%" align="left">
<select id="student" name="student">
<option value="0">choose...</option>
</select></td>
</tr>
</table>
</td>
ace_beta.php是緊密相連的select.class.php其中函數存儲...
CODE(select.class。 PHP)
<?php
class SelectList
{
protected $conn;
public function __construct()
{
$this->DbConnect();
}
protected function DbConnect()
{
include "db_config.php";
$this->conn = mysql_connect($host,$user,$password) OR die("Unable to connect to the database");
mysql_select_db($db,$this->conn) OR die("can not select the database $db");
return TRUE;
}
public function ShowClass()
{
$sql = "SELECT * FROM class";
$res = mysql_query($sql,$this->conn);
$class = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$class .= '<option value="' . $row['id_cls'] . '">' . $row['name'] . '</option>';
}
return $class;
}
public function ShowStudent()
{
$sql = "SELECT * FROM student WHERE id_cls=$_POST[id]";
$res = mysql_query($sql,$this->conn);
$student = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$student .= '<option value="' . $row['id_stu'] . '">' . $row['name'] . '</option>';
}
return $student;
}
}
$opt = new SelectList();
?>
問題
可有人是一種足以指導我雖然豪w至做到以下幾點:
- 基於「選課」的ace_beta.php,複選框 承載相應的同學會出現在ace_beta.php
- 中的「學生 區」名單方法來處理所選名稱,在 之後的ace_add.php中點擊「提交」按鈕。
我想幫助你,這是一個非常深思熟慮的問題,我很欣賞提出的時間和精力。只是一些澄清問題。你想顯示一個'>'而不是'
非常感謝您的回覆!理想情況下,我希望它會顯示一個複選框列表(早先你建議)與學生的名字從數據庫中繪製...謝謝,祝你聖誕節=) – Abel
這樣的事情http://checkboxtree.googlecode.com /svn/tags/checkboxtree-0.5.2/index.html?如果是的話,看看這個驚人的項目:http://code.google.com/p/checkboxtree/ – sdespont