title: Get data from php-foreach-loop to ajax
body: <p>I have searched very long for a solution to this problem but could not find any.</p>
  
  <p>I get data from the database to show some projects on my website. For each project i can click on a pen-symbol to edit the name of the project. I´d like to send the date per ajax request, but always get the data of the first project. If i try for example to edit the name of the second project "test", i get the data of the first project "blubb"</p>
  
  <p>What i have tried:
  - Used classes not Id´s 
  <a href="https://stackoverflow.com/questions/22376998/call-ajax-function-from-php-foreach-with-form">Call Ajax function from PHP foreach with form</a> 
  - Used  $this 
  <a href="https://stackoverflow.com/questions/18145838/get-ajax-variable-from-the-php-foreach-loops">Get Ajax variable from the PHP foreach loops</a></p>
  
  <p>My code lookes like this (simplified):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt; script type = "text/javascript" &gt;
    $(document).ready(function() {
      $(".submit").click(function() {
  
  //here are the problems, i only get the value of the first project
        var new_project_name = $('.new_project_name').val(); 
        var old_project_name = $('.old_project_name').val();
  
  
        $.ajax({
          type: "POST",
          url: "php/edit/edit.php",
          data: {
            old_project_name: old_project_name,
            new_project_name: new_project_name,
            name: name
          },
  
        }).
  
        done(function(response) {
          blabla
  
        });
      });
    }); &lt; /script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php foreach($db-&gt;query('SELECT * FROM portfolio ORDER BY position, id desc') as $row) { $name = $row['name']; ?&gt;
  
  &lt;div class="rename"&gt;
    &lt;table width="400" border="0" cellspacing="1" cellpadding="2"&gt;
      &lt;tr&gt;
        &lt;td&gt;Projektname:&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;
          &lt;input type="text" class="new_project_name" value="&lt;?php echo $name;?&gt;"&gt;
        &lt;/td&gt;
        &lt;input type="text" class="old_project_name" value="&lt;?php echo $name;?&gt;" hidden&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;
          &lt;input class="submit" type="submit" value="Umbenennen"&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  
  &lt;?php } ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank you for any help.</p>