Add value in name

0

I have a while, and I wanted each loop to be added a different value in name, two two select fields.

Ex: First loop first field comes: WeeklyPlan1

First loop first field comes: WeeklyGirl2

Does anyone have any ideas how I can do this?

Below the code I have:

<?php  
$i = 1;
while ($i <= 2) {
?>
<div class="container">
  <div class="jumbotron">
    <h1>Dados da primeira Criança</h1> 
<form action="">

  <div class="semanas-e-periodos">

     <div class="form-group">
    <label for="exampleFormControlSelect1">Semana</label>
    <select class="form-control" id="exampleFormControlSelect1" name="semanacrianca1">
      <option value="1semana">1º Semana</option>
      <option value="2semana">2º Semana</option>
      <option value="3semana">3º Semana</option>
      <option value="4semana">4º Semana</option>
      </select>
  </div>


     <div class="form-group">
    <label for="exampleFormControlSelect1">Semana</label>
    <select class="form-control" id="exampleFormControlSelect1" name="qtdcriancas">
      <option value="1">1 Criança</option>
      <option value="2">2 Crianças</option>
      <option value="3">3 Crianças</option>
      <option value="4">4 Crianças</option>
      <option value="5">5 Crianças</option>
    </select>
  </div>

  </div>

</form>

  </div>

<?
$i++;
}

?>
    
asked by anonymous 29.04.2018 / 00:59

2 answers

0

try to concatenate like this: 1. Create a counter for the weekly array and an array for qtdcriancas; then the replay loop will access them

<select class="form-control" id="exampleFormControlSelect1" name="<?php $semanacrianca1[$a] ?>">

">

++ $ a; ++ $ b;

Now it goes from your logic to make funfar

    
29.04.2018 / 01:08
0

Do this:

<?php  
 $i = 1;
 while ($i <= 2) {
?>
<div class="container">
 <div class="jumbotron">
  <h1>Dados da primeira Criança</h1> 
<form action="paginaAcao">

<div class="semanas-e-periodos">

<div class="form-group">
<label for="exampleFormControlSelect1">Semana</label>
<?php for($i=1;$i<=2;$i++){ ?>
  <select class="form-control" id="exampleFormControlSelect1" name="semanacrianca<?php echo $i?>">
   <option value="1semana">1º Semana</option>
   <option value="2semana">2º Semana</option>
   <option value="3semana">3º Semana</option>
   <option value="4semana">4º Semana</option>
  </select>
</div>
<?php } ?>
<div class="form-group">
<label for="exampleFormControlSelect1">Semana</label>
  <select class="form-control" id="exampleFormControlSelect1" name="qtdcriancas">
    <option value="1">1 Criança</option>
    <option value="2">2 Crianças</option>
    <option value="3">3 Crianças</option>
    <option value="4">4 Crianças</option>
    <option value="5">5 Crianças</option>
 </select>
</div>

</div>

</form>

</div>

<?php
 $i++;
 }
?>
    
29.04.2018 / 02:40