title: How to do a AJAX click post on every PHP foreach result
body: <p>I have read multiple sorts of answers but none works.
  what i try to do is to make every result from a PHP foreach loop clickable and then send that data with AJAX to a other PHP file, the problem now is that whatever i do, only the last foreach result always get send and not the result that i clicked on? (without Database)</p>
  
  <p>the loop exist in a function functions.php:</p>
  
  <pre><code>public function getForeachResult ()
  {
      $response = $this-&gt;GetObject($parameters);
  
          include 'template.php';
  }
  </code></pre>
  
  <p>the template that handles the result template.php:</p>
  
  <pre><code>&lt;?php
  foreach ($response-&gt;Result-&gt;List as $key =&gt;$value) {
  
      ?&gt;&lt;table id="mytable"&gt;&lt;tr&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Date&lt;/th&gt;
          &lt;th&gt;firstname&lt;/th&gt;
          &lt;th&gt;lastname&lt;/th&gt;
      &lt;/tr&gt;
  
      &lt;?php foreach ($value as $key=&gt;$value) {?&gt;
  
              &lt;tr class="myrow"&gt;
              &lt;td&gt;&lt;?php echo $value-&gt;ID; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo date("d-m-Y", strtotime($value-&gt;Time)); ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $value-&gt;FullName; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $value-&gt;LastName; ?&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
      &lt;?php } ?&gt;
  
      &lt;/table&gt;&lt;br /&gt;
  
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>In template.php the AJAX script is called at the bottom:</p>
  
  <pre><code>&lt;script&gt;
  $('.myrow').click(function() {
      $.ajax({
          type: "POST",
          cache: false,
          url: "post.php",
          data: { action: 'goTo', value: &lt;?php echo $value-&gt;ID ?&gt;}
      }).done(function( msg ) {
          $('.Data').html(msg);
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>In post.php where the dat is send i only get the last result of the foreach loop
  post.php:</p>
  
  <pre><code>if($_POST['action'] == 'goTo') {
      var_dump ($_POST);
  }
  </code></pre>
  
  <p>so how can i make sure AJAX sends the data that i clicked on?</p>