我在将两个值从数组传递到另一个网页时遇到了麻烦。
数组由两个值(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'];
}
?>
我的问题是,每次点击一个形状时,它只显示最后一个数组,而不是形状坐标的值。
答案 0 :(得分:0)
试试这个:
在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'];
}
?>