Я хотел бы поместить в эту динамическую c таблицу. К сожалению, я ничего не знаю о JS. Как мне создать этот echo (), чтобы каждый адрес получал собственный идентификатор из echo? . На данный момент это действительно не работает. Если я трижды щелкну «+» во второй записи, третий tr будет добавлен в первую таблицу.
<?php foreach ($view_postcard as $post_card): ?>
<table class="table table-borderless" id="tab_logic">
<thead>
<tr>
<th width="100" class="text-center" colspan="2">Briefmarke</th>
<th width="100" class="text-center">
<div class="btn-group">
<button type="button" class="btn btn-success btn-sm" id="add_row_<?php echo $post_card['post_card_id']; ?>">+</button>
<button type="button" class="btn btn-danger btn-sm" id="delete_row_<?php echo $post_card['post_card_id']; ?>">-</button>
</div>
</th>
</tr>
</thead>
<tbody>
<tr id="<?php echo $post_card['post_card_id']; ?>addr0">
<td><input type="number" class="form-control form-control-sm" name="add_karte_menge" min="1" max="5" value="1"></td>
<td colspan="2">
<select required class="form-control form-control-sm" name="add_briefmarke[]">
<option value="">-</option>
<?php foreach ($view_post_briefmarke as $briefmarke): ?>
<option value="<?php echo $briefmarke['tb_post_briefmarke_id'];?>"><?php echo number_format($briefmarke['tb_post_briefmarke_preis'],2,",","."); ?> Eur - Briefmarke</option>
<?php endforeach; ?>
</select>
</td>
<td></td>
</tr>
<tr id='<?php echo $post_card['post_card_id']; ?>addr1'></tr>
<script type="text/javascript">
$(document).ready(function(){
var i=1;
$("#add_row_<?php echo $post_card['post_card_id']; ?>").click(function(){
$('#<?php echo $post_card['post_card_id']; ?>addr'+i).html("<td><input type='number' class='form-control form-control-sm' name='add_karte_menge' min='1' max='5' value='1'></td><td colspan='2'><select required class='form-control form-control-sm' name='add_briefmarke[]'><option value=''>-</option><?php foreach ($view_post_briefmarke as $briefmarke): ?><option value='<?php echo $briefmarke['tb_post_briefmarke_id'];?>'><?php echo number_format($briefmarke['tb_post_briefmarke_preis'],2,',','.'); ?> Eur - Briefmarke</option><?php endforeach; ?></select></td><td></td>");
$('#tab_logic').append('<tr id="<?php echo $post_card['post_card_id']; ?>addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row_<?php echo $post_card['post_card_id']; ?>").click(function(){
if(i>1){
$("#<?php echo $post_card['post_card_id']; ?>addr"+(i-1)).html('');
i--;
}
});
});
</script>
</tbody>
</table>
<?php endforeach; ?>