 |
ช่วยดู code Menu list ให้หน่อยครับ ไม่รู้ code ผิดตรงไหน |
|
 |
|
|
 |
 |
|
ผมลองเอา code ของพี่วิน ตาม link https://www.thaicreate.com/community/dependant-listmenu-dropdownlist.html ไปใช้รวมกับ form ที่เตรียมไว้ครับ แต่พอ run บน browser มันไม่เป็นไปตามที่คาดสิครับ menu list มันแสดงผลแต่เฉพาะส่วนของ Geography แต่ Province กับ Amphur ไม่แสดงผลครับ ไม่รู้ code ไปผิดตรงไหน ผมเองยังไม่ค่อยแม่น code ด้วยสิ รบกวนผู้รู้มาแนะนำหน่อยครับ
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","root","nop") or die("Error Connect to Database");
$objDB = mysql_select_db("thailand");
@mysql_query("SET NAMES UTF8");
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check username</title>
<style type="text/css">
<!--
.style1 {color: #0000FF}
-->
</style>
</head>
<body>
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
frmMain.ddlProvince.length = 0
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["GEO_ID"];?>;
strValue = "<?=$objResult["PROVINCE_ID"];?>";
strItem = "<?=$objResult["PROVINCE_NAME"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["PROVINCE_ID"];?>;
strValue = "<?=$objResult["AMPHUR_ID"];?>";
strItem = "<?=$objResult["AMPHUR_NAME"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
<h1 class="style1">::Register::</h1>
<form action="register2.php" method="post" name="frmMain">
<table cellspacing = "2">
<tr>
<td><b>Username :</b></td>
<td><input name="user_reg" type="text" value="">*</td>
</tr>
<tr>
<td><b>Passwaord : </b></td>
<td><input name="pass_reg" type="password">*</td>
</tr>
<tr>
<td><b>ชื่อ-สกุล : </b></td>
<td><input name="name_reg" type="text">*</td>
</tr>
<tr>
<td><b>เพศ : </b></td>
<td><input name="sex_reg" type="radio" value="ชาย"
checked>
ชาย
<input name="sex_reg" type="radio" value+"หญิง">
หญิง</td>
</tr>
<tr>
<td><b>อีเมล :</b></td>
<td><input name="email_reg" type="text" size="26">*</td>
</tr>
<tr>
<td><b>โทรศัพท์ :</b></td>
<td><input name="tel_reg" type="text" size="26">*</td>
</tr>
<tr>
<td><b>ที่อยู่ติดต่อ :</b></td>
<td><input name="address_reg" cols="35" rows="3">
</textarea></td>
</tr>
<tr>
<td>Geography
</td>
<td><select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM geography ORDER BY GEO_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["GEO_ID"];?>"><?=$objResult["GEO_NAME"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<td>Province</td>
<td><select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)"></select>
</td>
</tr>
<tr>
<td>Amphur</td>
<td><select id="ddlAmphur" name="ddlAmphur" style="width:200px"></select></td>
</tr>
<tr>
<td> </td>
<td><input type="Submit" value="Submit">
<input type="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
<?
mysql_close($objConnect);
?>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-06-28 17:30:04 |
By :
nopasurada |
View :
1829 |
Reply :
11 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รันดูแล้วก็ปกติดีนะครับ
ลองเช็ค Database : thailand ดูนะครับ
และก็ Connection ครับ

|
 |
 |
 |
 |
Date :
2009-06-28 18:07:17 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองโหลด database thailand มาลงใหม่แล้วครับ ผมที่ได้เหมือนเดิมครับ ส่วนเรื่อง connection ลองเช็คดูก็ถูกต้องนะครับ ไม่รู้ผมเข้าใจถูกไหมว่า ถ้า connection ไม่ถูก ตรง Geopraphy ก็ไม่น่าจะแสดงผลได้ แต่ที่ผมเจอคือ Geopraphy แสดงผลแต่ Province กับ Amphur ไม่แสดงผล ช่วยบอกอีกทีได้ไหมครับ ว่าต้องเช็ค บรรทัดไหน จะไปเช็คละเอียดอีกที สงสัยว่าทำไม run ที่เครื่องคุณ P@e ถึงปกติ แต่ run เครื่องผมมีปัญหา
|
 |
 |
 |
 |
Date :
2009-06-28 23:49:24 |
By :
nopasurada |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะแก้ไข ส่วน connect นะ
บรรทัดที่ 1-5 เป็นการเรียกไฟล์ connect แทน <? require("connect.php"); ?>
แล้วปิดการเรียกใช้ mysql [บรรทัดที่ 171-173 ot
<?
//mysql_close($objConnect);
?>
แค่นี้ก็นำไปใช้ได้ ลองทำดูนะ บอกด้วยว่าจะทำได้ป่ะ
|
 |
 |
 |
 |
Date :
2009-06-29 09:52:31 |
By :
kai9 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีปัญหา ต้องช่วยกันแก้ไข
|
 |
 |
 |
 |
Date :
2009-06-29 09:54:03 |
By :
kai9 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ Nop มี Error ตรงไหน เอามาโพสบอกด้วยนะครับ
|
 |
 |
 |
 |
Date :
2009-06-29 10:06:08 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองตามวิธีของคุณ kai แล้วครับ ยังไม่ได้ ไม่มี error ใดๆ แต่ พอ run บน browser กลับแสดง webpage หน้าว่างๆ เลยครับ
|
 |
 |
 |
 |
Date :
2009-06-30 00:33:00 |
By :
nopasurada |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนผู้รู้มาตอบหน่อยครับ ต้องการความช่วยเหลือมากๆ
|
 |
 |
 |
 |
Date :
2009-06-30 20:43:31 |
By :
nopasurada |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีใครช่วยผมเลย เศร้า
|
 |
 |
 |
 |
Date :
2009-07-01 22:49:55 |
By :
nopasurada |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเห็นคุณพิมพ์หน้าฟอร์ม Passwaord สะกดผิดครับ ช่วยได้แค่เนี้ย ผมไม่ค่อยรู้เรื่องโคดครับ
|
 |
 |
 |
 |
Date :
2009-07-03 00:03:37 |
By :
STRIKEN98 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนชื่อ ตัวแปร 2 ตัวนี้ดูครับอย่าให้ซ้ำกัน ได้ผมหรือไม่ได้ผลบอกด้วยล่ะกัน
$strSQL
$objQuery
|
 |
 |
 |
 |
Date :
2009-07-03 11:44:44 |
By :
Redmansy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ หลังจากที่โง่มานาน เหมือนเส้นผมบังภูเขา แค่เอา code ข้างล่างออก จบเลยครับ
<!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">
ผมเอา code ล่าสุดที่ใช้ได้มาแปะ ไว้ด้วยเผื่อ คนอื่นจะเอาไปใช้บ้าง แต่สุดท้ายยังไม่เข้าใจว่าแค่เอา code ข้างบนออกก็ใช้ได้ งงมาก รบกวนผู้รู้มา comment หน่อยครับ ไขความกระจ่าง
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","root","nop") or die("Error Connect to Database");
$objDB = mysql_select_db("thailand");
@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check username</title>
<style type="text/css">
<!--
.style1 {color: #0000FF} -->
</style>
</head>
<body>
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
frmMain.ddlProvince.length = 0
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["GEO_ID"];?>;
strValue = "<?=$objResult["PROVINCE_ID"];?>";
strItem = "<?=$objResult["PROVINCE_NAME"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows1++;
?>
x = <?=$intRows1;?>;
mySubList = new Array();
strGroup = <?=$objResult["PROVINCE_ID"];?>;
strValue = "<?=$objResult["AMPHUR_ID"];?>";
strItem = "<?=$objResult["AMPHUR_NAME"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
<h1 class="style1">::Register::</h1>
<form action="register2.php" method="post" name="frmMain">
<table cellspacing = "2">
<tr>
<td><b>Username :</b></td>
<td><input name="user_reg" type="text" value="">*</td>
</tr>
<tr>
<td><b>Password : </b></td>
<td><input name="pass_reg" type="password">*</td>
</tr>
<tr>
<td><b>ชื่อ-สกุล : </b></td>
<td><input name="name_reg" type="text">*</td>
</tr>
<tr>
<td><b>เพศ : </b></td>
<td><input name="sex_reg" type="radio" value="ชาย"
checked>
ชาย
<input name="sex_reg" type="radio" value+"หญิง">
หญิง</td>
</tr>
<tr>
<td><b>อีเมล :</b></td>
<td><input name="email_reg" type="text" size="26">*</td>
</tr>
<tr>
<td><b>โทรศัพท์ :</b></td>
<td><input name="tel_reg" type="text" size="26">*</td>
</tr>
<tr>
<td><b>ที่อยู่ติดต่อ :</b></td>
<td><input name="address_reg" cols="35" rows="3">
</textarea></td>
</tr>
<tr>
<td>Geography
</td>
<td><select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM geography ORDER BY GEO_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["GEO_ID"];?>"><?=$objResult["GEO_NAME"];?></option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<td>Province</td>
<td><select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)"></select>
</td>
</tr>
<tr>
<td>Amphur</td>
<td><select id="ddlAmphur" name="ddlAmphur" style="width:200px"></select></td>
</tr>
<tr>
<td> </td>
<td><input type="Submit" value="Submit">
<input type="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
<?
mysql_close($objConnect);
?>
|
 |
 |
 |
 |
Date :
2009-07-07 03:44:25 |
By :
nopasurada |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|