|
|
|
ajax หรือ jquery ที่่กรอก textbox เดียวแล้วสามารถดึงค่าจากฐานข้อมูลมาแสดงรายละเอียดของรหัสที่เรากรอกเข้าไป ใครมีบ้างมั้ยคะ หาเท่าไหร่ก้อหาไม่เจอ เริ่มท้อแล้วค่ะ |
|
|
|
|
|
|
|
คือกรอก แค่ รหัสนักเรียนลงไป
ส่วน>>>>ชื่อ-สกุล ระดับการศึกษา เบอร์โทรจะออกมาเองน่ะค่ะ
|
|
|
|
|
Date :
2011-10-15 11:10:52 |
By :
yaifayCS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JavaScript
// Start XmlHttp Object
function uzXmlHttp(){
var xmlhttp = false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlhttp = false;
}
}
if(!xmlhttp && document.createElement){
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
// End XmlHttp Object
function getresult(){
// เอาค่าจาก form มาเก็บลง num1,num2
var num1 = document.form1.txtItemJob.value;
var num2 = document.form1.txtIncoterm.value;
var server_name = document.form1.txtServerName.value;
var result;
var url = 'http://'+server_name+'/po/system/application/views/ajax.php?num1=' + num1 + '&num2='+ num2;
//alert('num1 :'+num1);
//alert('num2 :'+num2);
//alert('url :'+url);
if(num1 == ""){
alert('กรุณาระบุ Item');
document.form1.txtItemJob.focus();
return false;
}
if(num2 == ""){
alert('กรุณาเลือก Incoterm');
document.form1.txtIncoterm.focus();
return false;
}
xmlhttp = uzXmlHttp();
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
// รับค่ากลับจาก server มาเก็บลง result
result = xmlhttp.responseText;
var respArray = result .split('|');
var resp1 = respArray[0];//USD
var resp2 = respArray[1];//THB
var resp3 = respArray[2];//PCS
var resp4 = respArray[3];//UNIT
var resp5 = respArray[4];//season
// นำค่าที่ได้ออกไปแสงผล
document.form1.txtPriceUsd.value = resp1;
document.form1.txtPrice.value = resp2;
document.form1.txtPcs.value = resp3;
document.form1.txtItemUnit.value = resp4;
document.form1.txtSeason.value = resp5;
}
Ajax.php
<?php
//$result = $num1 + $num2;
$num1 =$_GET['num1'];
$num2 =$_GET['num2'];
$host = 'velinux1:/space2/ve.gdb';
$dbh = ibase_connect($host, "SYSDBA","masterkey");
$query =("select * from master_price
where makefor ='QTP' And act ='Y'
And logo_item ='$num1' And incoterm ='$num2'");
$qry = ibase_query($dbh, $query);
$row = ibase_fetch_object($qry);
$result = $row->PRICE_USD;
$result2 = $row->PRICE_TH;
$pcs = $row->PCS;
$unit_type = $row->UNIT_TYPE;
$season = $row->SEASON;
print $result . "|" . $result2 . "|" . $pcs . "|" . $unit_type . "|" . $season ;
?>
ลองดูตัวอย่างที่ผมเคยทำนะครับ
ตอนกดค้นหาให้เรียกฟังชั่นนี้นะ "getresult();"
|
|
|
|
|
Date :
2011-10-15 11:26:13 |
By :
suaingam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากค่ะ ลองทำดูก่อนนะคะ
|
|
|
|
|
Date :
2011-10-15 11:38:25 |
By :
yaifayCS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไม่ได้อ่ะค่ะ
โค้ดของดิฉันเปนอย่างนี้ค่ะ
ควรแก้ตรงไหนดีคะ
Code (PHP)
<?
$db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
if($id_sent){
$sql="select * from tbl_student where std_no ='$id_sent'";
$re = $db->select_query($sql);
$data=$db->fetch($re);
}
if($id_sent2){
$sql2="select * from tbl_book where book_no ='$id_sent2' ";
$re2=$db->select_query($sql2);
$data2=$db->fetch($re2);
$sql2_type=$db->select_query("select * from type_book where type_id ='$data2[book_type]' ");
//echo $sql2_type; exit();
$data2_type=$db->fetch($sql2_type);
$sql="select * from tbl_student where std_no ='$id_sent2_' ";
$re=$db->select_query($sql);
$data=$db->fetch($re);
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link rel="stylesheet" type="text/css" href="../style.css">
<style type="text/css">
@charset "utf-8";
/* CSS Document */
.menuclick{background-color:#00CC33; color: #FFFFFF; font-size:14px; font-family:Microsoft Sans Serif; font-weight:bold;}
.menuclick2{background-color: #CCFF99; color: #CCFF99;}
.inputdata{ border:0; border-bottom:thin dashed #999999; background-color: #FFFFFF; color: #3399CC;font-family: "Microsoft Sans Serif";font-weight: normal; text-align: center;
font-size:14px; }
.inputtext{ border:0; border-bottom:thin dashed #999999; background-color: #FFFFFF; color: #3399CC;font-family: "Microsoft Sans Serif";font-weight: normal; text-align: left;
font-size:14px; }
.inputtext2{ border:0; border-bottom:thin dashed #999999; background-color: #FFFFFF; color: #000000;font-family: "Microsoft Sans Serif";font-weight: normal; text-align: left;
font-size:14px; }
.inputproject{ border:0; border-bottom:thin dashed #999999; background-color:#E7F4FF; color: #3399CC;font-family: "Microsoft Sans Serif";font-weight: normal; text-align: left;
font-size:14px; }
.text12 {
font-family: BrowalliaUPC, CordiaUPC;
font-size: 14px;
font-weight: normal;
color: #000000;
background-color: #FFFFFF;
text-align: center;
}
.textstyle2 {
font-family: "Microsoft Sans Serif";
font-weight: bold;
color: #999999;
}
.textstyle3 {
font-family: "Microsoft Sans Serif";
font-weight: normal;
color:#FF0000;
}
.text1 {
font-family: "Microsoft Sans Serif";
font-weight: bold;
color: #0099CC;
text-align:center;
}
.inputtextCopy {
background-color: #FFFFFF;
color: #000000;
font-family: "Microsoft Sans Serif";
font-weight: normal;
text-align: center;
font-size:14px;
border-top-width: 0;
border-right-width: 0;
border-bottom-width: thin;
border-left-width: 0;
border-bottom-color: #999999;
}
.style2Copy {
font-family: "Microsoft Sans Serif";
font-weight: normal;
color: #000000;
font-size: 14px;
background-color: #FFFFFF;
text-align: center;
}
<!--
#Layer1 {
position:absolute;
left:13px;
top:48px;
width:87px;
height:28px;
z-index:1;
}
#Layer2 {
position:absolute;
left:11px;
top:67px;
width:715px;
height:159px;
z-index:1;
}
.style8 {font-size: 18px}
.style10 {font-family: "Microsoft Sans Serif"; font-weight: bold; color: #0099CC; text-align: center; font-size: 24px; }
.style11 {font-family: "Microsoft Sans Serif"; font-weight: bold; color: #0099CC; text-align: center; font-size: 16px; }
.style3 {font-size: 16px}
.style45 { font-size: 18px;
font-weight: bold;
color: #FF0000;
}
a:link {
color: #FF0000;
}
a:visited {
color: #FF0000;
}
a:hover {
color: #FF0000;
}
a:active {
color: #FF0000;
}
.style46 {
color: #FF0000;
font-size: 18px;
}
.style47 {font-family: "Microsoft Sans Serif"; font-weight: bold; color: #FF0000; text-align: center; font-size: 16px; }
.style49 {
font-size: 24px;
font-weight: bold;
}
.style50 {color: #FF0000}
.style51 {color: #0000FF}
-->
</style>
<p align="left" class="style10"> </p>
<p align="left" class="style11"><img src="images/ตรวจสอบหนังสือค้างส่ง copy.gif" width="350" height="50" /></p>
<table width="705" border="0" align="center">
<tr>
<td height="102"><fieldset>
<legend class="style47">ข้อมูลสมาชิก</legend>
<table width="697" border="0">
<tr>
<td width="139" height="38" class="text1"><div align="right"><span class="inputtextCopy">รหัสนักเรียน</span> :</div></td>
<td width="220"><div align="left">
<form id="form1" name="form1" method="post" action="?name=admin&file=check_bill">
<label>
<input name="id_sent" type="text" id="id_sent" value="<?=$data[student_id]?>" readonly="readonly"/>
</label>
<? if($sent_id!=""){?>
<label>
<input type="submit" class="menuclick2" name="submit" value="5" id="submit" />
</label>
<? }?>
<a href="javascript:NewWindow('index2.php?name=admin&file=search_check','newpopup','600','300','center','front');"><span class="menuclick"> ค้นหา </span></a>
</form>
<label></label>
</div></td>
<td width="82" class="text1"><div align="right"><span class="inputtextCopy">ชื่อ - สกุล</span> :</div></td>
<td width="238"><div align="left">
<input name="name" size="25" type="text" disabled="disabled" id="name" value="<? echo "$data[intro]$data[name] ";?>" />
</div></td>
</tr>
<tr>
<td height="33" class="text1"><div align="right"><span class="inputtextCopy">ระดับการศึกษา</span> :</div></td>
<td><div align="left">
<input name="textfield4" type="text" disabled="disabled" id="textfield4" value="<?=$data[status_]?>" />
</div></td>
<td class="text1"><div align="right"><span class="inputtextCopy">เบอร์โทรศัพท์</span> :</div></td>
<td><div align="left">
<input name="tel" size="25" type="text" id="tel" value="<?=$data[tel]?>" disabled="disabled"/>
</div></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<?
function DateDiff($strDate1,$strDate2)
{
return (strtotime($strDate2) - strtotime($strDate1))/ ( 60 * 60 * 24 ); // 1 day = 60*60*24
}
$num_ber=1;
$se="select * from bookborow_sent where student_id= '$id_sent' and status_borrow=2 ";
//echo $se;
$se_=$db->select_query($se);
$d_d=date("d-m-Y");
while ($be_= $db->fetch($se_)){
//$d=date('d-m-Y',strtotime("+7 day"));
$date_cal= DateDiff("$be_[date_sent]","$d_d");
if($date_cal > 0 ){
$a1=1;
$num_cal+=$date_cal;
$date_cal_+=$date_cal * 5;
}
}
if($a1==1){
?>
<? }?> </td>
</tr>
<tr>
<td height="21"></td>
</tr>
</table>
<table width="724" height="122" border="0" align="center">
<tr>
<td width="731" valign="top"><fieldset>
<legend class="style47">รายการหนังสือที่ค้างส่ง</legend>
<table width="716" border="0">
<tr>
<td width="75" height="28" bgcolor="#FFFFCC" ><div align="center" class="inputproject">
<div align="center">รายการที่</div>
</div></td>
<td width="70" bgcolor="#FFFFCC" ><div align="center" class="inputproject">
<div align="center">รหัสหนังสือ</div>
</div></td>
<td width="255" bgcolor="#FFFFCC" ><div align="center" class="inputproject">
<div align="center">ชื่อหนังสือ</div>
</div></td>
<td width="94" bgcolor="#FFFFCC" ><div align="center" class="inputproject">
<div align="center">วันที่ยืม</div>
</div></td>
<td width="96" bgcolor="#FFFFCC" ><div align="center" class="inputproject">
<div align="center">กำหนดคืน</div>
</div></td>
<td width="100" bgcolor="#FFFFCC" ><div align="center" class="inputproject">
<div align="center">วันล่าช้า/ค่าปรับ</div>
</div></td>
</tr>
<? // echo $real ;exit();
if($id_sent2_){
$sql_="select * from bookborow_sent where student_id= '$id_sent2_' and status_borrow=1";
//echo sql_ ; exit();
}else if($id_sent){
$sql_="select * from bookborow_sent where student_id= '$id_sent' and status_borrow=1 ";
}else{
$sql_="select * from bookborow_sent where 0 ";
}
//echo $sql_ ; exit();
$re_=$db->select_query($sql_);$i=1;
while ( $data_=$db->fetch($re_)){
$date1 = $data_["date_sent"];
$date2 = $data_["date_borrow"];
$dates1=thaiDate($date1);
$dates2=thaiDate($date2);
$sql_book=$db->select_query("select * from tbl_book where book_no='$data_[book_isbn]' ");
$data_book=$db->fetch($sql_book);
$sql_type=$db->select_query("select * from type_book where type_id='$data_book[book_type]' ");
$data_type=$db->fetch($sql_type);
//echo
// echo $data_[date_sent];
$date2= DateDiff("$data_[date_sent]","$d_d"); //echo $date2;
if($date2 > 0 ){
$num_cal=$date2;
$date_cal_=$date2 * 5;
//echo $date_cal_;
$total_cal+=$date2 * 5;
//$num_cal=0;
//$date_cal_=0;
}
?>
<tr>
<td height="38" bgcolor="#FFFFCC" class="inputtext"><div align="center">
<?=$i;?>
</div></td>
<td height="38" bgcolor="#FFFFCC" class="inputtext"><div align="center">
<?=$data_book[book_isbn];?>
</div></td>
<td bgcolor="#FFFFCC" class="inputtext"><div align="left">
<?=$data_book[book_name];?>
</div></td>
<td bgcolor="#FFFFCC" class="inputtext"><?=$dates2;?></td>
<td bgcolor="#FFFFCC" class="inputtext"><div align="center">
<?=$dates1;?>
</div></td>
<td bgcolor="#FFFFCC" class="inputtext"><div align="center"><?=$num_cal?> วัน <?=$date_cal_?> บาท</div></td>
</tr> <? $i++; }?>
<tr>
<td height="28" colspan="6" bordercolor="#FFFFCC" bgcolor="#FFFFFF" ><div align="right">ยอดเงินที่ต้องชำระค่าปรับ<span class="style8">
<?=$total_cal?>
</span> บาท </div></td>
</tr>
<tr>
<td height="28" colspan="6" bordercolor="#FFFFCC" bgcolor="#FFCCCC" ><div align="right" class="text12 style49"><span class="style51">รวมหนังสือที่ค้างส่งทั้งหมด</span> <span class="style51">:</span> <span class="style50"><?=$i-1;?>
</span> <span class="style51">เล่ม</span> </div>
<div align="left"></div></td>
</tr>
</table>
</fieldset></td>
</tr>
</table>
<div align="center"></div>
<? if($chk!=""){
$sql_up="update tbl_book set book_num=$book_num+1 where book_no='$id_book' ";
$db->select_query("update bookborow_sent set status_borrow=2 where borow_no='$chk' ");
$db->select_query($sql_up);
//echo $sql_up ; exit();
if($sql_up){echo"<script>alert('ระบบได้รับรายการที่คืนเรียบร้อยแล้ว')</script>"; echo "<script>window.location='?name=admin&file=BookSent& id_sent=$id_sent '</script>";}
}?>
|
|
|
|
|
Date :
2011-10-15 16:38:16 |
By :
yaifayCS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|