Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ทำ AutoFill พิมพ์ id แล้วข้อมูลไม่แสดงน่ะครับ ไม่ติด error แต่ข้้อมูลใน DB ไม่แสดงออกมา



 

ทำ AutoFill พิมพ์ id แล้วข้อมูลไม่แสดงน่ะครับ ไม่ติด error แต่ข้้อมูลใน DB ไม่แสดงออกมา

 



Topic : 090856



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์




ตอนนี้ไม่ติด error อะไรนะครับ แต่ข้อมูลไม่แสดงออกมาเท่านั้นเองครับ รบกวนด้วยครับ

อ้างอิงหน้านี้ครับ

https://www.thaicreate.com/community/jquery-auto-fill-textbox.html

ตัวอย่างที่ 2 การทำ Auto Fill ข้อมูล โดยกรอกเพียงแค่ CustomerID และข้อมูลอื่น ๆ แสดงผลอัตโนมัติ


ฐานข้อมูลที่ต้องการให้แสดงครับ

position

หน้าคำสั่ง DB

Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
</head>
<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("police_mamber");
$strSQL = "SELECT * FROM position  WHERE 1 AND idposition = '".$_POST["sid"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
<body>
</body>
</html>




Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {	font-size: xx-large;
	font-weight: bold;
}
</style>

<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("police_mamber");
mysql_db_query($dbname,"SET NAMES tis620"); 
mysql_query("SET character_set_database ='tis620'"); 
mysql_query("SET character_set_results ='tis620'"); 
mysql_query("SET character_set_client ='tis620'"); 
mysql_query("SET character_set_connection ='tis620'"); 
mysql_query("SET character_set_system ='tis620'"); 
mysql_query("collation_connection = tis620_thai_ci"); 
mysql_query("collation_database = tis620_thai_ci"); 
mysql_query("collation_server = tis620_thai_ci"); 
?>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
		$("#txtidposition").change(function(){
				$.ajax({
					url: "reposition.php" ,
					type: "POST",
					data: 'sid=' +$("#txtidposition").val()
				})
				.success(function(result) {
						var obj = jQuery.parseJSON(result);
						if(obj == '')
						{
									$('input[type=text]').val('');
						}
						else
						{
						$.each(obj, function(key, inval) {
						$("#txtidposition").val(inval["idposition"]);
						$("#txtpositionname").val(inval["positionname"]);
});
}
});
});
});

</script>



</head>


<body>

<table width="865" border="1" align="center">
<tr>  </tr>
</table>
<tr><td height="10" bgcolor="#FFFFFF">&nbsp;</td>


        &nbsp;  <table width="356"   align="center" border="1">
          <tr>
            <td width="121">เลขตำแหน่ง</td>
            <td width="219"><input type="text" id="txtidposition" name="txtidposition" size="20">&nbsp;</td>
          </tr>
          <tr> 
            <td>ตำแหน่ง</td>
            <td><input type="text" id="txtpositionname" name="txtpositionname" size="20">&nbsp;</td>
          </tr>
          <tr>
</body>
</html>




Tag : PHP, MySQL









ประวัติการแก้ไข
2013-02-14 11:30:46
2013-02-14 11:32:26
2013-02-14 11:33:14
2013-02-14 11:33:57
2013-02-17 22:10:39
2013-02-17 22:11:20
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-02-14 11:29:31 By : puldool View : 1030 Reply : 26
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
reposition.php


ลองเรียกไฟล์นี้ตรง ๆ มี error หรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-14 12:36:35 By : mr.win
 


 

No. 2



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มีแต่รูป [] นี้ขึ้นครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-14 12:55:54 By : puldool
 

 

No. 3



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


คิดว่าข้อมูลตรงนะครับ แต่ไม่รุ้ว่าผิดตรงไหน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-14 17:59:35 By : puldool
 


 

No. 4



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


รบกวนพี่ๆช่วยดูให้หน่อยนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-17 22:09:23 By : puldool
 


 

No. 5



โพสกระทู้ ( 5,105 )
บทความ ( 4 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


idposition ของน้องเป็น int
แต่ของตัวอย่าง
CustomerID เป็น varchar
มองเบื้องต้นคร่าว ๆ อาจจะเป็นจากตรงนี้.....

แก้อย่างไร ลองเพิ่ม ฟิลด์ id สักอย่างเก็บข้อมูล varchar
ส่วน idposition ให้มันอยู่ของมันไปเฉย ๆ ไม่ต้องไปยุ่งครับ

จากอันนี้
Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {	font-size: xx-large;
	font-weight: bold;
}
</style>

<?
/* บรรทัดนี้
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("police_mamber");
mysql_db_query($dbname,"SET NAMES tis620"); 
mysql_query("SET character_set_database ='tis620'"); 
mysql_query("SET character_set_results ='tis620'"); 
mysql_query("SET character_set_client ='tis620'"); 
mysql_query("SET character_set_connection ='tis620'"); 
mysql_query("SET character_set_system ='tis620'"); 
mysql_query("collation_connection = tis620_thai_ci"); 
mysql_query("collation_database = tis620_thai_ci"); 
mysql_query("collation_server = tis620_thai_ci"); 
ถึงอันนี้ เอามาทำอะไร เอาออกได้เปล่า */
?>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
		$("#txtidposition").change(function(){
				$.ajax({
					url: "reposition.php" ,
					type: "POST",
					data: 'sid=' +$("#txtidposition").val()
				})
				.success(function(result) {
						var obj = jQuery.parseJSON(result);
						if(obj == '')
						{
									$('input[type=text]').val('');
						}
						else
						{
						$.each(obj, function(key, inval) {
						$("#txtidposition").val(inval["idposition"]);
						$("#txtpositionname").val(inval["positionname"]);
});
}
});
});
});

</script>



</head>


<body>

<table width="865" border="1" align="center">
<tr>  </tr>
</table>
<tr><td height="10" bgcolor="#FFFFFF">&nbsp;</td>


        &nbsp;  <table width="356"   align="center" border="1">
          <tr>
            <td width="121">เลขตำแหน่ง</td>
            <td width="219"><input type="text" id="txtidposition" name="txtidposition" size="20">&nbsp;</td>
          </tr>
          <tr> 
            <td>ตำแหน่ง</td>
            <td><input type="text" id="txtpositionname" name="txtpositionname" size="20">&nbsp;</td>
          </tr>
          <tr>
</body>
</html>



ประวัติการแก้ไข
2013-02-17 23:09:10
2013-02-17 23:13:57
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-17 23:07:35 By : apisitp
 


 

No. 6



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

รูปแบบ Data ที่ส่งไปผิดครับ
data: {sid:$("#txtidposition").val()}
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-17 23:29:34 By : Krungsri
 


 

No. 7



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ลองทำตามที่ำี่พี่ทั้ง 2 บอกแล้วนะครับ แต่ข้อมูลยังไม่ขึ้่นให้เลย


testdb


จากนั้นก็ลองรันดู็ก็ยังไม่ขึ้นครับ

และลองแก้จาก

Code (PHP)
data: 'sid=' +$("#txtidposition").val()


เป็น


Code (PHP)
data: {sid:$("#txtidposition").val()}





1234


ประวัติการแก้ไข
2013-02-17 23:50:16
2013-02-17 23:51:26
2013-02-17 23:52:13
2013-02-17 23:52:42
2013-02-17 23:59:30
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-17 23:49:33 By : puldool
 


 

No. 8



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

Code (PHP)
<script>
	$(document).ready(function(e) {
        $("#txtidposition").change(function(e) {
            $.ajax({
				url:"reposition.php",
				type:"POST",
				data:{sid:$(this).val()},
				dataType:"jason",
				success: function(data){
					alert(data);// ลอง alert ดูก่อนว่า มาป่าว มันจะเป็น Object ถ้าหากเป็น JSON 
				}
			});
        });
    });
</script>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:18:58 By : Krungsri
 


 

No. 9



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ไม่มีอะไรขึ้นเลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:28:15 By : puldool
 


 

No. 10



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

ไฟล์ reposition.php ลองเปลี่ยนเป็นแบบ GET ก่อน $_GET["sid"]

แล้วลองพิมที่ URL : localhost/ชื่อ root/reposition.php?sid=xxxx

xxxx ลองใส่ที่มีอยู่จริง หากไม่มีอะไรโชว์มา ก็คงผิดที่หน้านี้ ลองดูครับเอาใจช่วย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:35:39 By : Krungsri
 


 

No. 11



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ข้อมูลขึ้นครับพี่

http://127.0.0.1/reposition.php?sid=1234

ผลที่ออกมา
[{"idposition":"1234","positionname":"1234","division":"","ampur":"","station":"","positiondivition":"","positionlevel":""}]


ประวัติการแก้ไข
2013-02-18 00:39:48
2013-02-18 00:40:25
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:38:59 By : puldool
 


 

No. 12



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

ถ้าข้อมูลขึ้นครบ คงผิดที่ $.ajax

ไฟล์อยู่ที่เดียวกันป่าว ไม่ได้อยู่ต่าง Folder นะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:42:46 By : Krungsri
 


 

No. 13



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ที่เดียวกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:45:18 By : puldool
 


 

No. 14



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

อย่าลืมเปลี่ยน reposition.php เป็น POST ก่อนละ
Code (PHP)
<script>
	$(document).ready(function(e) {
        $("#txtidposition").change(function(e) {
            $.ajax({
				url:"reposition.php",
				type:"POST",
				data:{sid:$(this).val()},
				dataType:"jason",
				success: function(data){
					$.each(data,function(key,val){
						$("#txtpositionname").val(val.positionname);
					});
				}
			});
        });
    });
</script>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:47:53 By : Krungsri
 


 

No. 15



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ยังไม่ขึ้นครับ ทำตามที่พี่บอก

Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
</head>
<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("police_mamber");
$strSQL = "SELECT * FROM position  WHERE 1 AND idposition = '".$_POST["sid"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
<body>
</body>
</html>


Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {	font-size: xx-large;
	font-weight: bold;
}
</style>

<script>
	$(document).ready(function(e) {
        $("#txtidposition").change(function(e) {
            $.ajax({
				url:"reposition.php",
				type:"POST",
				data:{sid:$(this).val()},
				dataType:"jason",
				success: function(data){
					alert(data);// ลอง alert ดูก่อนว่า มาป่าว มันจะเป็น Object ถ้าหากเป็น JSON 
				}
			});
        });
    });
</script>

          <input type="text" id="txtidposition" name="txtidposition" size="20">
      
      
         <input type="text" id="txtpositionname" name="txtpositionname" size="20">

</head>

<body>



ประวัติการแก้ไข
2013-02-18 00:53:24
2013-02-18 00:53:34
2013-02-18 00:57:17
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:51:36 By : puldool
 


 

No. 16



โพสกระทู้ ( 342 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("police_mamber");
$strSQL = "SELECT * FROM position  WHERE 1 AND idposition = '".$_GET["sid"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:57:41 By : weaned
 


 

No. 17



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

<input type="text" id="txtidposition" name="txtidposition" size="20">
<input type="text" id="txtpositionname" name="txtpositionname" size="20">

เอาไว้ ใน <body></body> สิ แก้เป็น $_POST["sid"] ด้วยเพราะ ajax ส่งมาแบบ pOST


ประวัติการแก้ไข
2013-02-18 00:59:38
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 00:58:25 By : Krungsri
 


 

No. 18



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


แบบนีี้้้นะครับ แต่ยังไม่ได้เลย

Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {	font-size: xx-large;
	font-weight: bold;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
		$("#txtidposition").change(function(){
				$.ajax({
					url: "reposition.php" ,
					type: "POST",
					data: {sid:$("#txtidposition").val()}
				})
				.success(function(result) {
						var obj = jQuery.parseJSON(result);
						if(obj == '')
						{
									$('input[type=text]').val('');
						}
						else
						{
						$.each(obj, function(key, inval) {
						$("#txtidposition").val(inval["idposition"]);
						$("#txtpositionname").val(inval["positionname"]);
});
}
});
});
});
</script>
</head>
<body>

<table width="865" border="1" align="center">
<tr>  </tr>
</table>
<tr><td height="10" bgcolor="#FFFFFF">&nbsp;</td>


        &nbsp;  <table width="356"   align="center" border="1">
          <tr>
            <td width="121">เลขตำแหน่ง</td>
            <td width="219"><input type="text" id="txtidposition" name="txtidposition" size="20">&nbsp;</td>
          </tr>
          <tr> 
            <td>ตำแหน่ง</td>
            <td><input type="text" id="txtpositionname" name="txtpositionname" size="20">&nbsp;</td>
          </tr>
          <tr>
</body>
</html>



ประวัติการแก้ไข
2013-02-18 01:10:18
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:08:28 By : puldool
 


 

No. 19



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

ลองอันนี้
Code (PHP)
<!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>Untitled Document</title>
<style type="text/css">
.style1 {	font-size: xx-large;
	font-weight: bold;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
		$("#txtidposition").change(function(){
				$.ajax({
					url: "reposition.php" ,
					type: "POST",
					data: {sid:$(this).val()},
					dataType:"jason",
					success: function(result){
						$.each(result,function(k,v){
							$("#txtidposition").val(v.idposition);
							$("#txtpositionname").val(v.positionname);
						});
					}
				});
		});
});
</script>
</head>
<body>

<table width="865" border="1" align="center">
<tr>  </tr>
</table>
<tr><td height="10" bgcolor="#FFFFFF">&nbsp;</td>


        &nbsp;  <table width="356"   align="center" border="1">
          <tr>
            <td width="121">เลขตำแหน่ง</td>
            <td width="219"><input type="text" id="txtidposition" name="txtidposition" size="20">&nbsp;</td>
          </tr>
          <tr> 
            <td>ตำแหน่ง</td>
            <td><input type="text" id="txtpositionname" name="txtpositionname" size="20">&nbsp;</td>
          </tr>
          <tr>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:14:49 By : Krungsri
 


 

No. 20



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


พี่ๆนอนพักก่อนไหมครับ ถ้าเกินเวลาพี่ๆ พักก่อนก็ได้นะครับ

ยังไม่ออกเลยครับ ToT


Code (PHP)
<!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=windows-874" />
<title>Untitled Document</title>
</head>
<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("police_mamber");
$strSQL = "SELECT * FROM position  WHERE 1 AND idposition = '".$_POST["sid"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
<body>
</body>
</html>



ประวัติการแก้ไข
2013-02-18 01:22:13
2013-02-18 01:24:48
2013-02-18 01:27:57
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:19:56 By : puldool
 


 

No. 21



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

dataType:"jason", เปลี่ยนเป็น dataType:"json", ลองดูผมน่าจะพิมพ์ผิด
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:33:51 By : Krungsri
 


 

No. 22



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เปลี่ยน ให้เป็น json เหมือนกันแล้วครับ แต่ยังไม่ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:36:19 By : puldool
 


 

No. 23



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

ลองสร้าง Table มาใหม่ใน DB เดิม แล้วลองสร้างไฟล์ใหมาตามนี้
Code (SQL)
CREATE TABLE `type` (
  `T_id` int(4) NOT NULL auto_increment COMMENT 'รหัสประเภท',
  `T_name` varchar(50) collate utf8_unicode_ci default NULL COMMENT 'ชื่อประเภท',
  PRIMARY KEY  (`T_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;


INSERT INTO `type` VALUES (1, 'Type1');
INSERT INTO `type` VALUES (2, 'Type2');
INSERT INTO `type` VALUES (3, 'Type3');

TestFill.php
<!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>Untitled Document</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
		$("#txtidposition").blur(function(){
				$.ajax({
					url: "get.php" ,
					type: "POST",
					data: {ID:$(this).val()},
					dataType:"json",
					success: function(result){
						$.each(result,function(k,v){
							$("#txtidposition").val(v.T_id);
							$("#txtpositionname").val(v.T_name);
						});
					}
				});
		});
});
</script>
</head>
<body>
        <table width="356"   align="center" border="1">
          <tr>
            <td width="121">เลขตำแหน่ง</td>
            <td width="219"><input type="text" id="txtidposition" name="txtidposition" size="20">&nbsp;</td>
          </tr>
          <tr> 
            <td>ตำแหน่ง</td>
            <td><input type="text" id="txtpositionname" name="txtpositionname" size="20">&nbsp;</td>
          </tr>
          <tr> 
            <td colspan="2" align="center"><button type="button">แสดง</button></td>
          </tr>
          </table>
</body>
</html>


get.php
<?
header('Content-Type: text/html; charset=utf-8');

#######################################  Class ในการแปลงเป็น json
class mysql2json{
 public static function getJSON($resultSet,$affectedRecords){
 $numberRows=0;
 $arrfieldName=array();
 $i=0;
 $json="";
	//print("Test");
 	while ($i < mysql_num_fields($resultSet))  {
 		$meta = mysql_fetch_field($resultSet, $i);
		if (!$meta) {
		}else{
		$arrfieldName[$i]=$meta->name;
		}
		$i++;
 	}
	 $i=0;
	  $json="[\n";
	while($row=mysql_fetch_array($resultSet, MYSQL_NUM)) {
		$i++;
		//print("Ind ".$i."-$affectedRecords<br>");
		$json.="{\n";
		for($r=0;$r < count($arrfieldName);$r++) {
			$json.=" \"$arrfieldName[$r]\" :	\"$row[$r]\"";
			if($r < count($arrfieldName)-1){
				$json.=",\n";
			}else{
				$json.="\n";
			}
		}
		if($i!=$affectedRecords){
		 	$json.="\n},\n";
		}else{
		 	$json.="\n}\n";
		}	
	}
	$json.="\n]";
	return $json;
 }
}
#######################################


$con = mysql_connect('localhost','root','1234');
mysql_select_db('test_navicat');
$result = mysql_query("SELECT * FROM type WHERE T_id='".$_POST['ID']."'");
$num = mysql_num_rows($result);

$jason = mysql2json::getJSON($result,$num);
echo $jason;
?>



ประวัติการแก้ไข
2013-02-18 01:46:16
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:45:34 By : Krungsri
 


 

No. 24



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ได้แล้วครับ ขอบคุณมากๆครับ


ประวัติการแก้ไข
2013-02-18 01:58:23
2013-02-18 01:59:37
2013-02-18 02:00:00
2013-02-18 02:04:05
2013-02-18 02:06:41
2013-02-18 02:09:06
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 01:58:01 By : puldool
 


 

No. 25



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

ลองประยุกต์ดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 02:07:31 By : Krungsri
 


 

No. 26



โพสกระทู้ ( 280 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เปลี่ยนจาก $.each(result,function(k,v) เป็น $.each(result,function(v,v) ขอบคุณมากๆเลยครับพี่
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-18 02:09:54 By : puldool
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ทำ AutoFill พิมพ์ id แล้วข้อมูลไม่แสดงน่ะครับ ไม่ติด error แต่ข้้อมูลใน DB ไม่แสดงออกมา
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่