[英]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.