|
|
|
ขอถามเกี่ยวกับ list menu ดึงข้อมูลมาจาก Database ครับ |
|
|
|
|
|
|
|
-ฝั่ง client
<script language="javascript" type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
else
{
alert("Browser Error!!!");
}
}
function RequestNewStatus()
{
createXMLHttpRequest();
var id = document.getElementById("id");
xmlHttp.open("GET","server.php?id="+id.value+"&random="+Math.random(),true);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
ResponseNewStatus(xmlHttp);
}
}
xmlHttp.send(null);
}
function ResponseNewStatus(xmlHttp)
{
var returnVal = xmlHttp.responseText;
var textbox = document.getElementById("n_name");
textbox.value = returnVal;
}
</script>
<form name="form1" method="post" action="#">
<select name="id" id="id" onchange="RequestNewStatus();">
<option value=""></option>
<?
$connect = mysql_connect("localhost","","");
mysql_select_db("gallery",$connect);
$sql = "SELECT * FROM [table]";
$result = mysql_query($sql,$connect);
while($data = mysql_fetch_array($result))
{
echo"<option value=\"$data[gal_id]\">$data[field_name]</option>";
}
?>
</select>
<input type="text" id="n_name" name="n_name" />
</form>
-ฝั่ง server
$connect = mysql_connect("localhost","","");
mysql_select_db("gallery",$connect);
$id = $_GET['id'];
if(strcmp($id,"") != 0)
{
$sql = "SELECT * FROM [table] WHERE [field] = $id";
$result = mysql_query($sql,$connect);
$data = mysql_fetch_array($result);
echo $data[field];
mysql_close($connect);
}
else
{
echo" ";
}
|
|
|
|
|
Date :
8 เม.ย. 2551 17:43:02 |
By :
kinkop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตรง
xmlHttp.open("GET","server.php?id="+id.value+"&random="+Math.random(),true);
เปลี่ยน server.php เป็น url ที่คุณจะส่งค่าไปเองอ่ะครับ
|
|
|
|
|
Date :
8 เม.ย. 2551 17:44:56 |
By :
kinkop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thank a lot.
|
|
|
|
|
Date :
8 เม.ย. 2551 18:28:02 |
By :
kwan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วถ้า ในส่วนของ ID ของผมมันมีตัวอักษรภาษาอังกฤษ เช่น 05A001 มันไม่สามารถเรียกใช้ fuction ได้ครับ
ต้องแก้ไขตรงไหนครับ
ตรงส่วนนี้รึปล่าครับ xmlHttp.open("GET","server.php?id="+id.value+"&random="+Math.random(),true);
|
|
|
|
|
Date :
9 เม.ย. 2551 13:34:07 |
By :
kwan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|