我有一個名爲bargraph.php
的php文件,它創建了一個條形圖圖像。我在使用seprate文件graph.php
進口bargraph.php
:如何使用會話變量創建PHP圖像
<img src='bargraph1.php'>
但我需要使用會話變量來創建條形圖。我需要傳遞可變年份值以在bargraph.php中生成圖像。但它不顯示圖形。我甚至嘗試過使用ajax。它沒有發生。
graph.php
<script>
alert(<?php echo $year ?>);
var ids = $year;
if (ids == "") {
document.getElementById("graph").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");
}
var data = "year=" + ids ;
//var year ="year=" +id1;
xmlhttp.open("POST", "bargraph1.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(data);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("graph").innerHTML=xmlhttp.responseText;
}
}
</script>
和
bargraph1.php
我使用下面的代碼:
$year = $_POST['year'];
$sql = "SELECT dt,dist,cal FROM demo where YEAR(dt)='$year'";
$result = mysql_query($sql,$con);
爲什麼不通過GET提供年,即'bargraph1.php?year = 2012'。更簡單,更直觀(每年都有獨特的URL)。 – dtech
我試過使用這個,但仍然是我的一年值沒有得到bargraph1.php..plz建議其他方法,如果可能的話... – shivani