|
|
|
list manu ถ้าไม่ใช้ java มาช่วย ใช้แต่ php อย่างเดียวได้ไหม |
|
|
|
|
|
|
|
Code (PHP)
<?php
<select name="province" id="province">
<option value=" ">:: Province ::</option>
<?php
$sql = "select * from province
order by province_name";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
for ($i=1;$i<=$num;$i++){
$row = mysql_fetch_array($result);
?>
<option value="<?php echo $row["province_id"] ?>"><?php echo $row["province_name"] ?></option>
<?php }?>
</select>
?>
ไมรู้ตรงที่ต้องการหรือป่าวน่ะ
|
|
|
|
|
Date :
2009-05-11 00:38:04 |
By :
kanchen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเอาโค้ดนี้ไปทดสอบดูครับ
ผมใช้ php เขียนส่วนใหญ่ แต่ขอมี javascript ปนอยู่หน่อยนะครับ
Code (PHP)
<?php
/**
* Thai Geography Selection
*
*/
/**
*
* @author num <dragon_html[At]hotmail.com>
* @version thai geography selection v1.0b
*
* usage
* 1. download database file at
* https://www.thaicreate.com/free-web-script/dependent-listmenu-dropdownlist.html
* 2. create database name thailand and use it or use other database
* 3. import thailand.sql into the database of part number 2.
* 3. change localhost, root, 12345 to your server,username,password
*/
mysql_connect('localhost','root','12345');
mysql_select_db('thailand');
mysql_query('SET NAMES UTF8');
$s = '';
$case = @$_GET['CASE'];
if (empty($case)){
$case = !empty($_GET['GEO_ID'])?'GEO_ID':null;
$case = !empty($_GET['PROVINCE_ID'])?'PROVINCE_ID':$case;
$case = !empty($_GET['AMPHUR_ID'])?'AMPHUR_ID':$case;
$case = !empty($_GET['DISTRICT_ID'])?'DISTRICT_ID':$case;
}
switch($case){
case 'DISTRICT_ID':
$r = mysql_query('SELECT * FROM `district` WHERE `DISTRICT_ID`='.(int)$_GET['DISTRICT_ID']) or report();
if (mysql_num_rows($r)){
$_GET['AMPHUR_ID'] = mysql_result($r,0,'AMPHUR_ID');
}
case 'AMPHUR_ID':
$r = mysql_query('SELECT * FROM `district` WHERE `AMPHUR_ID`='.(int)$_GET['AMPHUR_ID']) or report();
if (mysql_num_rows($r)){
$_GET['PROVINCE_ID'] = mysql_result($r,0,'PROVINCE_ID');
$s = strOption('DISTRICT_NAME','DISTRICT_ID',@$_GET['DISTRICT_ID'],'-- ตำบล --',$r).$s;
}
case 'PROVINCE_ID':
$r = mysql_query('SELECT * FROM `amphur` WHERE `PROVINCE_ID`='.(int)$_GET['PROVINCE_ID']) or report();
if (mysql_num_rows($r)){
$_GET['GEO_ID'] = mysql_result($r,0,'GEO_ID');
$s = strOption('AMPHUR_NAME','AMPHUR_ID',@$_GET['AMPHUR_ID'],'-- อำเภอ --',$r).$s;
}
case 'GEO_ID':
$r = mysql_query('SELECT * FROM `province` WHERE `GEO_ID`='.(int)$_GET['GEO_ID']) or report();
if (mysql_num_rows($r)){
$s = strOption('PROVINCE_NAME','PROVINCE_ID',@$_GET['PROVINCE_ID'],'-- จังหวัด --',$r).$s;
}
$r = mysql_query('SELECT * FROM `geography`') or report();
$s = strOption('GEO_NAME','GEO_ID',@$_GET['GEO_ID'],'-- ภาค --',$r).$s;
break;
default :
$r = mysql_query('SELECT * FROM `geography`') or report();
$s = strOption('GEO_NAME','GEO_ID',null,'-- ภาค --',$r).$s;
}
mysql_close();
/**
* @param string $valueCol Column Name of Option Value
* @param string $idCol Column Name of Option Text
* @param string $id Value of Selected Option
* @param string $head First Option's Text
* @param resource $result Resoure returned from mysql_query(SELECT_QUERY)
* @return string Complete HTML Selecte Tag
*/
function strOption($valueCol,$idCol,$id,$head,$result){
$s = "\n<select name='{$idCol}' onchange='if ("{$idCol}"=="DISTRICT_ID"){return;}this.form.CASE.value="{$idCol}";this.form.submit();'>";
$s .= "\n<option value='0'>".htmlspecialchars($head)."</option>";
while($row = mysql_fetch_assoc($result)){
$s.= ($row[$idCol]===$id)
?"\n<option value='{$row[$idCol]}' selected='selected'>"
:"\n<option value='{$row[$idCol]}'>";
$s.= htmlspecialchars($row[$valueCol]);
$s.= "</option>";
}
$s.= '</select>';
return $s;
}
/**
* @return string MySQL Error Report
*/
function report(){
return die(htmlspecialchars(mysql_error()));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="th" xml:lang="th">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>geography selection</title>
</head>
<body>
<form action="?" method="get">
<input type="hidden" name="CASE" />
<?php echo $s; ?>
<input type="submit" />
</form>
</body>
</html>
reference
http://cakephp.jitwitya.com/post/thai-geography-selection-dropdown-listbox
|
|
|
|
|
Date :
2009-05-11 11:21:09 |
By :
num |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อยากทำให้บันทึกเป็น name ไม่ได้เป็น ID ได้ ครับ
|
|
|
|
|
Date :
2010-12-23 00:07:34 |
By :
jerawatdy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|