|
|
|
อยากทราบวิธีทำ auto select ครับ แบบว่า เลือก user จากลิตเมนูแล้ว ข้อมูลของ user จะแสดงออกมาเลย โดยไม่ต้องกด submit ครับ |
|
|
|
|
|
|
|
index.php
Code (PHP)
<?php
require("Connections/connect_db.php");
?>
<script type="text/javascript">
function showMember(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","data.php?q="+str,true);
xmlhttp.send();
}
</script>
<form name="form1">
<select name="memner" onchange="showMember(this.value)">
<option value="0">เลือก Member</option>
<?
mysql_select_db($database_connect_db, $connect_db);
mysql_query("set NAMES tis620");
$strSQL = "SELECT member_id,name FROM member";
$result = mysql_query( $strSQL, $connect_db);
while ( $rs = mysql_fetch_array($result))
{
if ($rs['member_id'] == $memner)
echo "<option value=\"$rs[member_id]\" selected>$rs[name]</option>\n"
else
echo "<option value=\"$rs[member_id]\">$rs[name]</option>\n";
}
?>
</select>
</form>
<div id="txtHint"><b>Table info will be listed here.</b></div>
<?php
mysql_close($connect_db);
?>
data.php
Code (PHP)
<?php
require("Connections/connect_db.php");
$member_id = $_GET["q"];
$sql="SELECT name,surname,sex FROM member WHERE member_id = '".$member_id."' ";
$result = mysql_query($sql);
?>
<table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr height="35">
<td><div align="center"><h4>name</h4></div></td>
<td><div align="center">surname</div></td>
<td><div align="center">sex</div></td>
</tr>
<?php
while($fd = mysql_fetch_array($result)) {
?>
<tr>
<td><div align="center"><?php echo $fd['name']; ?></div></td>
<td><div align="center"><?php echo $fd['surname']; ?></div></td>
<td><div align="center"><?php echo $fd['sex']; ?></div></td>
</tr>
<?php
} //end while
mysql_close($connect_db);
?>
|
ประวัติการแก้ไข 2012-01-19 13:43:51
|
|
|
|
Date :
2012-01-19 13:41:44 |
By :
avsqlz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|