title: counting the rows in html table using php
body: <p>I have got a dynamic HTML table that allows the user to add rows on click of a button. The data from each row needs to be inserted in MySQL table for which i use the PHP script. Now since each time the number of rows in the HTML table may be different, how do I deal with this in PHP. One way is to count the number of rows in HTML table (which I found somewhere to be done like this) </p>
  
  <pre><code>$rows = $table-&gt;find('#studenttable'); /*line 4 of my code*/
  $count = count($rows);                 /*studenttable is the id of my table*/
  echo $count;
  </code></pre>
  
  <p>and then run a for loop for inserting the data for each row. But that is giving a fatal error.</p>
  
  <p><code>Notice: Undefined variable: table in savedata.php on line 4</code></p>
  
  <p><code>Fatal error: Call to a member function find() on a non-object in savedata.php on line 4</code></p>
  
  <p>The other way round may be to use a foreach loop which I am completely not getting how to implement in this situation.</p>
  
  <p>This code dynamically adds new rows</p>
  
  <pre><code>var count=2;
  
  function addRow()
  {
  
  
  var table=document.getElementById("studenttable");
  var row=table.insertRow(-1);
  var cell15=row.insertCell(14);
  
  var ipt8 = document.createElement('input');
      ipt8.setAttribute("type", "hidden");
      ipt8.name = "htmlrow[]";      
      ipt8.value = count;        
      cell15.appendChild(ipt8);
  count++;
  }
  </code></pre>
  
  <p>PHP file to get the number of rows</p>
  
  <pre><code>&lt;?php
  $arr = $_POST['htmlrow'];
  foreach ($arr as $val) {
     $count= $val;
  echo $count;
  
  }
  ?&gt;
  </code></pre>
  
  <p>still not getting result.</p>