简体   繁体   中英

Trouble in passing a value from array in another page

I'm having a trouble in passing two values from an array to another web page.

The array is composed of two values (lotx and loty) which I got from a query.
I want to pass the value of lotx and loty or the coordinates of the shape when clicked.

The code below shows how I created shapes whose coordinates are x = lotx and 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>

And I want to display the lot_x and lot_y in pass.php after clicking the shape (the code is written below)

<?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'];
}
?>

My problem is that every time I clicked a shape, it's only showing the last array not the value of coordinates of the shape.

Try this:

In 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'];
   }
 ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM