title: How to collect data from dynamic HTML table
body: <p>I have a page with a HTML table with newsfacts (NIEUWSBERICHT), photos (IMAGE) and ads (RECLAME). On this page  the user can organize these items by adding a pagenumber to them. After saving the pagenumbers to the db, the items with a pagenumber will be broadcast in an edition of the cablenewspaper (or whatever you call it in English), which is the final goal. The HTML table also shows the foreign keys I need for my queries.</p>
  
  <p>There's an image of the HTML table at: </p>
  
  <p><img src="https://i.stack.imgur.com/0r170.png" alt="enter image description here"></p>
  
  <p>My problem is: how can I collect the data from the above HTML table after submitting the form? </p>
  
  <p>I want to get 2 types of queries like (for example; keys correspond with the above picture):</p>
  
  <pre><code>UPDATE NIEUWSBERICHT SET pagenumber = 2 WHERE nieuwsbericht_id = 53
  UPDATE NIEUWSBERICHT SET pagenumber = 3 WHERE nieuwsbericht_id = 56
  UPDATE NIEUWSBERICHT SET pagenumber = 6 WHERE nieuwsbericht_id = 62
  </code></pre>
  
  <p>and</p>
  
  <pre><code>UPDATE IMAGE SET pagenumber = 7 WHERE image_id = 19
  </code></pre>
  
  <p>What makes it difficult for me is that the HTML table is build up dynamically (in PHP) and the number of rows is variable. See listing below. Somehow I think it would be better if I let go of the dynamically building of the table and start using arrays to store all variables in instead of "$cell". Or maybe I can somehow get the PageNo-item in the screen get multiple values, like in the picture the PageNo on the first row gets the values 20 and 8, which I can use in the query. Aahhhrrg, I just don't know how to continue anymore. Anyone please?</p>
  
  <pre><code>// Get column names //
  $fields_num = mysql_num_fields($result);
  echo "&lt;h1&gt;Create edition {$table}&lt;/h1&gt;";
  echo "&lt;table border='1'&gt;&lt;tr&gt;";
  for($i=0; $i&lt;$fields_num; $i++)
      {
      $field = mysql_fetch_field($result);
      echo "&lt;td&gt;{$field-&gt;name}&lt;/td&gt;";
      }
  echo "&lt;td&gt;PageNo&lt;/td&gt;";
  echo "&lt;/tr&gt;\n";
  
  // Show query result //
  while($row = mysql_fetch_array($result, MYSQL_ASSOC))
      {
  echo "&lt;tr&gt;";
  foreach($row as $cell)
      echo "&lt;td&gt;$cell&lt;/td&gt;";
  echo "&lt;td&gt; &lt;select  name='paginanummer'&gt;
      &lt;option&gt;&lt;/option&gt;
      &lt;option&gt;1&lt;/option&gt;
      &lt;option&gt;2&lt;/option&gt;
      &lt;option&gt;3&lt;/option&gt;
      &lt;option&gt;4&lt;/option&gt;
      &lt;option&gt;5&lt;/option&gt;
      &lt;option&gt;6&lt;/option&gt;
      &lt;option&gt;7&lt;/option&gt;
      &lt;option&gt;8&lt;/option&gt;
      &lt;option&gt;9&lt;/option&gt;
      &lt;option&gt;10&lt;/option&gt;
      &lt;/select&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;\n";
      }
  </code></pre>
  
  <p>Wow, it's become quite a story. Hope I did it all right.</p>