title: Update MySQL with jQuery pulldown in foreach loop
body: <p>I have been having as issue for a while, and can not seem to wrap my head around it. I have a dropdown menu that is pulled from a database for the status of an item. </p>
  
  <pre><code>$myQuery2 = "SELECT InventoryItemStatus.InventoryItemStatusID, InventoryItemStatus.InventoryItemStatusDescription FROM InventoryItemStatus";
  $result2 = mysql_query($myQuery2) or die (mysql_error());
  if(mysql_num_rows($result2)){ 
      $select2= '&lt;select style="width:90px" name="StatusList"&gt;';
          while($rs=mysql_fetch_array($result2)){
                  $select2.='&lt;option value="'.$rs['InventoryItemStatusID'].'"&gt;'.$rs['InventoryItemStatusDescription'].'&lt;/option&gt;';                        
              }
  }
  $select2.='&lt;/select&gt;';
  </code></pre>
  
  <p>Easy. Now my goal is to update the database with jQuery/AJAX without reloading the page. I figured out how to do that by using the following code.</p>
  
  <pre><code>$(document).ready(function(){
    $('[name="StatusList"]').each(function() {
      $(this).change(function() {
      var mydata = $('[name="StatusList"]').val();//$(this).val();
      var inputdata = $('[name="StarmontInventoryItemID"]').val();
      $.ajax({   
         type: 'POST',   
         url: 'update_status/update_starmont.php',   
         data: {StatusList:mydata ,StarmontInventoryItemID:inputdata}
      });
      });
    });
  });
  </code></pre>
  
  <p>No problem. This code listens for a change on the pulldown, when activated calls a script and updates the database accordingly. The issue I am having that is driving me insane is I need this dropdown to appear for every inventory item I have. For example I do a query at the beginning of my code, which pulls 10 inventory items. Then what I do is a foreach in php to allow me to pull each item separately. What I am trying to do is have this dropdown appear for each of those 10 items, and when changed it will update the database for the appropriate inventory item. What is happening right now is that the dropdown that appears at the top of the list works, it will update as I want it too. But for the following 9, it just doesnt work and I can not figure out why.</p>
  
  <p>Here is my foreach loop. </p>
  
  <pre><code>&lt;?php
  if (sizeof($rows14) &gt; 0) {
  foreach($rows14 as $row14):
  
  
  $myQuery2 = "SELECT InventoryItemStatus.InventoryItemStatusID, InventoryItemStatus.InventoryItemStatusDescription FROM InventoryItemStatus";
  $result2 = mysql_query($myQuery2) or die (mysql_error());
  if(mysql_num_rows($result2)){ 
      $select2= '&lt;select style="width:90px" name="StatusList"&gt;';
          while($rs=mysql_fetch_array($result2)){
                  $select2.='&lt;option value="'.$rs['InventoryItemStatusID'].'"&gt;'.$rs['InventoryItemStatusDescription'].'&lt;/option&gt;';                        
              }
  }
  $select2.='&lt;/select&gt;';
  
  echo"
  &lt;tr class='tableRowClass2'&gt;
  &lt;td height='20'&gt;{$row14['OnHand']}&lt;/td&gt;
  &lt;td height='20'&gt;{$row14['ItemName']} - {$row17['StarmontSystemID']} - {$row17['StarmontSerial']}&lt;/td&gt;
  &lt;td height='20'&gt;
      &lt;form method='post'&gt;
      {$select2}
      &lt;input type='hidden' value='{$row14['InventoryItemID']}' name='StarmontInventoryItemID'/&gt;
      &lt;/form&gt;
  &lt;/td&gt;
  &lt;/tr&gt;";
  endforeach;
  }
  ?&gt;
  </code></pre>
  
  <p>As you can see, when the dropdown changes, I want to update the InventoryItemID with the appropriate status. What I dont understand is why the first one works, but the rest following after do not? Could it be something like I have to set a flag?</p>
  
  <p>I have tried multiple different things such as moving the query for the dropdown inside the foreach loop, outside it, a combination but I just cant seem to get it to work! Please any help or advise would be greatly appreciated.</p>
  
  <p>Thanks for you time!</p>