I kept trying and I was able to get the results I was looking for. In fact, this is a quite easy process.
What I did was to save the info from the inputs as a matrix, then loop over it and execute the query after every loop, simple as that.
I am providing some example codes. They are different from the table I have provided with the question, but the principles are the same.
The first thing I did was to format the names of the inputs as below. It made easier to loop over the arrays. The credit for this part belongs to the first answer of this post: Submitting a multidimensional array via POST with php
<tr>
<td><input name="info[0][top]" value="tr 1/ td 1" /></td>
<td><input name="info[0][bottom]" value="tr 1/ td 2" /></td>
</tr>
<br/>
<tr>
<td><input name="info[1][top]" value="tr 2/ td 1" /></td>
<td><input name="info[1][bottom]" value="tr 2/ td 2" /></td>
</tr>
<br/>
<tr>
<td><input name="info[2][top]" value="tr 3/ td 1" /></td>
<td><input name="info[2][bottom]" value="tr 3/ td 2" /></td>
</tr>
After that I just loop over the data coming from the form before executing the query.
$query = "INSERT INTO tb_teste (teste_info1, teste_info2) VALUES (:teste_info1, :teste_info2)";
$stmt = $this->conexao->prepare($query);
$el = $this->teste->__get('teste_info1');
$i = 0;
foreach ( $el as $item ) {
$stmt->bindValue(':teste_info1', $this->teste->__get('teste_info1')[$i]['top']);
$stmt->bindValue(':teste_info2', $this->teste->__get('teste_info1')[$i]['bottom']);
$stmt->execute();
$i++;
}
About the need of having a dynamic number of rows, I'll just create an input in JavaScript for every id that is generated and attribute the index of 'info' to a variable that will be incremented as it is needed. This will give me everything I need.