Add value in name

Asked

Viewed 31 times

0

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

Ex: First loop first field comes: weekday1

First loop first field comes: weekday2

Does anyone have any idea how I do it?

Down with the code I got:

<?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++;
}

?>
  • name="weekly child<? php echo $i">

  • ops name="weekly child<? php echo $i ?>">

  • Very good guy worked out, thanks @Leocaracciolo

2 answers

0


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

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

">

++$the; ++$b;

now it goes from your logic to funfar

0

Do so:

<?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++;
 }
?>
  • E method="METHOD"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.