|
 |
|
ช่วยดูให้ทีนะคะ มันกลับมาป่วนอีกครั้งแล้วค่ะ จะส่งโปรเจคอีกครั้งแต่โปรแกรมดันรวนค่ะ |
|
 |
|
|
 |
 |
|
จะส่งโปรเจคอีกครั้งแต่โปรแกรมดันรวนค่ะ
<?php
if (isset($_GET['load'])){
header('Content-type:text/html;charset=tis-620');
$student_id = $_POST['student_id'];
mysql_connect('localhost','','');
mysql_select_db('voting');
//@mysql_select_db('SET NAMES TIS620');
@mysql_query('SET NAMES TIS620');
//เปลี่ยน scode= เป็น columnname= ที่เก็บรหัสนักศึกษา
$r = mysql_query("SELECT fname,name,surname FROM student WHERE student_id='{$student_id}'");
if (mysql_num_rows($r)){
echo mysql_result($r,0);
}else{
echo 'not found student code '.$student_id;
}
exit();
}
?>
<!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" dir="ltr" lang="th" xml:lang="th">
<head>
<title>load data</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<script src="jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
/*<![CDATA[*/
$(document).ready(function(){
//กำหนด event hanlder สำหรับ event click ปุ่ม load
$('#load').click(function(){
//นำค่าจาก textbox scode มาเก็บไว้ในตัวแปร
var s = $('#student_id').val();
//request แบบ Ajax
$.ajax({
data:{student_id:s}, //ส่งตัวแปร s ไปทาง $_POST['scode']
url:'?load', //ส่งตัวแปรไปทาง url ?load
type:'POST', //ส่งแบบ POST
dataType:'html', //รับข้อมูลแบบ html
success:function(data){ //callback function หลังจากได้รับข้อมูลคืนกลับมา
$('#name').text(data);
},
error:function(){
alert('error');
}
});
});
});
/*]]>*/
</script>
</head>
<body>
<form>
<br /><input type="text" name="student_id" id="student_id" />
<br /><input type="button" id="load" value="load" />
<div id="name"></div>
<br /><input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
ถาม 2 อย่างนะคะ
1. พอใส่รหัสนักศึกษาและกด load แล้ว ขึ้นแค่คำนำชื่อเท่านั้น อย่างเช่น นาย หรือ นางสาวเท่านั้นค่ะ ตัวแปร name และ surname ไม่แสดงออกมา
2. อย่างที่พี่ num เคยตอบมาแต่ยังงง ถ้าช่องรหัสนักศึกษามีอีก 2 ช่อง ต้องเพิ่มตรง code php และ javascript ตรงไหนคะ ช่วยทีนะคะ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-06-28 08:07:45 |
By :
น้องเอ๋ |
View :
795 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ได้แล้วค่ะ แค่เปลี่ยน
echo mysql_result($r,0);
เป็น
echo implode(' ',mysql_fetch_assoc($r));
ค่ะ
แต่อยากถามว่า
ในตารางนี้ จะมีเก็บ fname , name และ surname รวมไปถึง id_faculty คือรหัสคณะ และ id_major คือรหัสสาขา โดยที่ id ทั้ง 2 ตัวนี้จะไปอ้างอิงกับตาราง faculty ที่มี id_faculty และ name_faculty และ ตาราง major ที่มี id_major และ name_major ไปค้นหาอ่ะค่ะ และจะแสดงข้อมูลตรงนี้ยังไงดีคะ
ช่วยทีนะคะ
|
 |
 |
 |
 |
Date :
2009-06-28 08:55:13 |
By :
น้องเอ๋ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|