[英]Trouble in passing a value from array in another page
將兩個值從數組傳遞到另一個網頁時遇到麻煩。
該數組由我從查詢中獲得的兩個值(lotx和loty)組成。
我想在單擊時傳遞lotx和loty的值或形狀的坐標。
下面的代碼顯示了如何創建坐標為x = lotx
和y = loty
<?php
try {
$stmt1=dbConnect()->prepare("SELECT l.LOT_NO, l.LOT_X, l.LOT_Y FROM lot_details AS l INNER JOIN type AS t, area a where l.LOT_STATE='available' and t.TYPE_NO=l.TYPE_NO and a.AREA_NO=t.AREA_NO and a.AREA_NO='1'");
$stmt1->execute();
} catch(PDOException $ex) {
echo "An Error occured!";
some_logging_function($ex->getMessage());
}
$count = $stmt1->rowCount();
$arr = array();
$ctr=0;
while($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) {
$arr[$ctr][0]= $row1['LOT_X'];
$arr[$ctr][1]= $row1['LOT_Y'];
$ctr++;
}
?>
</div>
<script type="text/javascript">
var arr1= <?php echo json_encode($arr); ?>;
var imgURL = document.getElementById("bg_image").src;
var myImg = new Image();
myImg.src = imgURL;
var width = myImg.width;
var height = myImg.height;
var paper = Raphael("canvas", width, height);
for(var i=0;i<arr1.length;i++){
var circle = paper.circle(arr1[i][0], arr1[i][1], 4);
var lx=arr1[i][0];
var ly=arr1[i][1];
circle.attr({fill: "red"}); circle.click(function(e)
{
window.location.href="pass.php?lot_x=" + lx + "&lot_y=" + ly;
});
}
</script>
我想在單擊形狀后在pass.php中顯示lot_x和lot_y(代碼寫在下面)
<?php
include 'config.php';
?>
<?php
if(isset($_GET['lot_x']) and isset($_GET['lot_x'])) {
echo $_GET['lot_x']; ?> <br> <?php
echo $_GET['lot_y'];
}
?>
我的問題是,每次單擊形狀時,它僅顯示最后一個數組,而不顯示形狀的坐標值。
嘗試這個:
在html中:
window.location.href="pass.php?lot_x=" + lx[] + "&lot_y=" + ly[];
PHP:
<?php
if(isset($_GET['lot_x']) and isset($_GET['lot_x'])) {
echo $_GET['lot_x']; ?> <br> <?php
echo $_GET['lot_y'];
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.