将数组中的值传递到另一页时遇到麻烦

Trouble in passing a value from array in another page

本文关键字:一页 遇到 麻烦 数组 值传      更新时间:2023-09-26

我在将两个值从数组传递到另一个网页时遇到了麻烦。

数组由两个值(lotx和loty)组成,这两个值是我从查询中得到的。
我想传递lotx和loty的值,或者在单击时传递形状的坐标。

下面的代码显示了我如何创建坐标为x = lotxy = 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'];
   }
 ?>