ต้องเขียน code ทำ list meun ของ department กับ position ใครได้ช่วยหน่อยนะคะ
เอาแบบง่ายๆ น้อ ไม่ต้องใช้ ajax
Code (PHP)
<select name="department" onchange="location.href= '?department=' + this.value">
ลูปจาก db แล้วเช็คแบบนี้
<option value="<?php echo $datafromdb; ?>" <?php if(isset($_GET['department']) and $_GET['department'] == $datafromdb){ echo ' selected="selected"'; }?>><?php echo $datafromdb; ?></option>
</select>
<select name="position">
ลูปจาก db โดยใช้ $sql = "select position_id, positon_name from where department_id = '" . $_GET['department'] . "'"
</select>
หวังว่าจะเข้าใจสิ่งที่ผมอธิบายน้อ
Date :
2011-02-13 23:45:58
By :
PlaKriM
ลองทำแล้วแต่ทำไม positionมันไม่แสดง
---------------------------------------------------------------------------------------------------------------------
mysql_select_db($database_dbhe, $dbhe);
$query_Recordset1 = "SELECT * FROM department";
$Recordset1 = mysql_query($query_Recordset1, $dbhe) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_dbhe, $dbhe);
$query_Recordset2 = "select position_id, position_name from position where department_id = '" . $_GET['department'] . "'";
$Recordset2 = mysql_query($query_Recordset2, $dbhe) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<form name="form1" method="post" action="">
<label><span class="style1">Department
<select name="department" onchange="location.href=departmentmenu.php'?department=' + this.value">
<?php
do {
?>
<option value="<?php $row_Recordset1['department_name']; ?>" <?php if(isset($_GET['department']) and $_GET['department'] == $row_Recordset1['department_name']){ echo ' selected="selected"'; }?>>
<?php echo $row_Recordset1['department_name']; ?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</span></label>
<p class="style1">
<label></label>
<label>
Position
<select name="position" id="position">
<?php
do {
?>
<option value="<?php echo $row_Recordset2['position_id']?>"><?php echo $row_Recordset2['position_name']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</label>
</p>
</form>
ไม่รู้ว่าผิดตรงไหน ขอรบกวนช่วยดูให้อีกครั้งนะคะ
ขอบคุณคะ
Date :
2011-02-14 02:07:04
By :
sas
Code (PHP)
$query_Recordset2 = "select position_id, position_name from position where 1=1";
if(){
$query_Recordset2 .= " and department_id = '" . $_GET['department'] . "'";
}
Date :
2011-02-14 10:20:13
By :
PlaKriM
ไม่ได้คะ มัน error ที่
mysql_select_db($database_dbhe, $dbhe);
$query_Recordset1 = "SELECT * FROM department ";
$Recordset1 = mysql_query($query_Recordset1, $dbhe) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_dbhe, $dbhe);
$query_Recordset2 = "SELECT * FROM `position` where 1=1";
if(){
$query_Recordset2 .= " and department_id = '" . $_GET['department'] . "'";
}
$Recordset2 = mysql_query($query_Recordset2, $dbhe) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
}
?>
<form name="form1" method="post" action="">
<label><span class="style1">Department
<select name="department" onchange="location.href=departmentmenu.php?department=' + this.value">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['department_id']; ?>" <?php if(isset($_GET['$department']) and $_GET['$department'] == $row_Recordset1['department_id']){ echo '"selected="selected"'; }?>>
<?php echo $row_Recordset1['department_name']; ?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</span></label>
<p class="style1">
<label></label>
<label>
Position
<select name="position" id="position">
<?php
do {
?>
<option value="<?php echo $row_Recordset2['position_id']?>"><?php echo $row_Recordset2['position_name']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</label>
</p>
<p class="style1"> </p>
</form>
Date :
2011-02-14 21:08:08
By :
sas
ERROR ที่บรรทัด 40
Parse error: syntax error, unexpected ')' in C:\AppServ\www\test\departmentmenu.php on line 40
Date :
2011-02-14 21:13:05
By :
sas
ขอโทษๆ ลืม
Code (PHP)
$query_Recordset2 = "select position_id, position_name from position where 1=1";
if(isset($_GET['department']) and !empty($_GET['department'])){
$query_Recordset2 .= " and department_id = '" . $_GET['department'] . "'";
}
Date :
2011-02-15 03:23:50
By :
PlaKriM
ขอบคุณมากคะ
Date :
2011-02-17 21:52:12
By :
sas
Load balance : Server 04