 |
สอบถามเกี่ยวกับการ GET ค่าที่ได้รับจาก List box ส่งไปยังไฟล์สร้างกราฟด้วย jpgraph |
|
 |
|
|
 |
 |
|
คือผมต้องการที่จะส่งค่าจาก Value ของ List box (ส่งไปจากไฟล์ database_climate.php) ไปยังไฟล์ที่สร้างกราฟ (test_link.php) ซึ่งผมได้ทำการส่งค่าไป แต่ค่าที่ได้นั้น เมื่อเอาไปแทรกในคำสั่ง sql มันไม่สามารถนำค่าที่ส่งไป ไปใช้ได้อ่ะครับ แต่ผมลองตั้งตัวแปร
ในไฟล์ test_link.php โดยให้ค่าของตัวแปรเหมือนกันกับค่าที่ถูกส่งมาจากไฟล์ database_climate.php แล้วลองนำไปแทรกในคำสั่ง
sql ดูใหม่ มันกลับใช้งานได้เฉยเลย ผมจึงไม่เข้าใจว่าทำไมค่าที่ถูกส่งมามันถึงนำไปใช้งานไม่ได้ ทั้งๆที่ค่ามันก็เหมือนกันกับค่าในตัวแปร
ที่ผมลองตั้งขึ้นมา ท่านใดเคยมีประสบการณ์แบบนี้ รบกวนชี้แนะด้วยครับ โค้ดด้านล่างครับ
ไฟล์ database_climate.php เป็นไฟล์ที่ Get ค่าไปแบบ Ajax (jquery)
Code (PHP)
<SCRIPT LANGUAGE="JavaScript">
<!--
function refStr(){
var x = Math.floor(Math.random() * 1000000);
return "refreshstring="+x;
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
$(document).ready(function(){
$('#txt_serch_graph').calendarsPicker({dateFormat:'dd-mm-yyyy'});
$('#btn_serch').button();
// --------------- Select Time BETWEEN ----------------
$("#btn_serch").click(function(){
$.get("test_link.php?"+refStr(),
{ option:"water_level", tao:"1750", pin:"1770"},
function(data){
//$("#wl").html("<img src=\"test_link.php\" title='tao_testo'>");
$("#wl").html(data);
}
)
});
});
//-->
</SCRIPT>
ไฟล์ test_link.php เป็นไฟล์ที่รับค่ามาจากไฟล์ database_climate.php
Code (PHP)
<?
include ("src/jpgraph.php");
include ("src/jpgraph_bar.php");
include ("src/jpgraph_line.php");
include("common.php");
$tao = $_GET['tao']; //ตัวแปรที่ผม GET ค่าเข้ามาแล้วใช้งานไม่ได้
$pin = $_GET['pin'];
//$tao = 1750; // ตัวแปรที่ผมกำหนดค่าให้เหมือนกับค่าที่ GET เข้ามา แต่ตัวแปรนี้ใช้งานได้
//$pin = 1770;
$sql = "select * from graph where id between '$tao' and '$pin' order by id asc "; //แทรกในคำสั่ง sql
$qry = mysql_query($sql);
$time = array();
while($rsl = mysql_fetch_array($qry)) {
$time[] = substr($rsl[time_date],0,5);
}
// ------------------ WL ------------------------
$sql = "select * from graph where id between '$tao' and '$pin' order by id asc ";
$qry = mysql_query($sql);
$wl = array();
while($rsl = mysql_fetch_array($qry)) {
$wl[] = $rsl[wl];
}
//--------------Size of the overall graph--------
$width=450;
$height=250;
// ---------Create the graph and set a scale.
// These two calls are always required-------------
$graph = new Graph($width,$height);
$graph->SetScale('textlin');
// ---------Setup margin and titles-------------
$graph->SetMargin(40,20,20,50);
$graph->title->Set('Water Level');
$graph->title->SetColor('#33CC00');
$graph->subtitle->Set('(March 12, 2008)');
$graph->subtitle->SetColor('#33CC00');
$graph->xaxis->title->Set('Time()');
$graph->xaxis->title->SetColor('red');
$graph->xaxis->title->SetMargin(14);
$graph->yaxis->title->Set('Water Level (m)');
$graph->yaxis->title->SetColor('blue');
// ----------Create the linear plot-----------
$lineplot=new LinePlot($wl);
$lineplot->SetColor( '#336600' );
//$lineplot->SetWeight( 2 ); // Two pixel wide
$lineplot->mark->SetType(MARK_IMG_DIAMOND,5,0.2,4);
$lineplot->mark->SetColor('blue');
$lineplot->mark->SetFillColor('red');
//$lineplot->value->Show();
//------- Enable X and Y Grid-------
$graph->xgrid->Show();
$graph->xgrid->SetColor('[email protected]');
$graph->xgrid->SetLineStyle('dashed');
$graph->ygrid->SetColor('[email protected]');
$graph->ygrid->SetLineStyle('dashed');
//$graph->yaxis->SetColor('blue');
//$graph->xaxis->SetColor('blue');
$graph->xaxis->SetTickLabels($time);
$graph->xaxis->SetFont(FF_COURIER,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(90);
//---------- Add the plot to the graph-------
$graph->Add($lineplot);
//---------- Display the graph--------------
$graph->Stroke();
mysql_close($con);
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
|
 |
 |
 |
 |
Date :
2013-01-22 18:58:16 |
By :
prcancle-13 |
View :
1424 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูแบบนี้ครับ
Code (JavaScript)
<script type="text/javascript">
$(document).ready(function(){
$("#btn1").click(function(){
$.get("jQueryget.php", {
data1: $("#txt1").val(),
data2: $("#txt2").val()},
function(data){
$("#div1").html(data);
}
);
});
});
</script>
jQuery.get() - Ajax , jQuery
|
 |
 |
 |
 |
Date :
2013-01-22 20:59:25 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาคือคุณจะต้องส่งค่าเข้าไปใน Ajax ให้ได้ก่อนน่ะครับ 
|
 |
 |
 |
 |
Date :
2013-01-23 05:47:08 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|