Because blank spaces are generated in my input value

2

<input type="text" class="form-control txt_respuesta54_act" name="txt_respuesta54_act" required value="
<?php
  if ($trim == 1){echo trim($respuesta_Trans_Q2);}
  elseif ($trim == 2){echo $respuesta_Trans_Q3;}
  elseif ($trim == 3){echo $respuesta_Trans_Q4;}
  elseif ($trim == 4){echo $respuesta_Trans_Q1;}
?>">

This code does retrieve from the BD values depending on the current value of $ trim, the problem arises in the blank spaces that precede the input, the result of the image is the way in which it shows them .

    
asked by Julio Flores 30.01.2018 в 23:22
source

1 answer

1

It would not be convenient for you to save a variable and then echo that variable? It would even be better to work with a switch (since it will be a little more orderly)

<?php
  switch ($trim) {
     case(1): $rpta = trim($respuesta_Trans_Q2); break;
     case(2): $rpta = $respuesta_Trans_Q3); break;
     case(3): $rpta = $respuesta_Trans_Q4); break;
     case(4): $rpta = $respuesta_Trans_Q1); break;
     default: $rpta = "no recuperado... mensaje default"; break;
  }
?>


<input type="text" class="form-control txt_respuesta54_act" name="txt_respuesta54_act" required value="<? echo $rpta; ?">

By the way, could you tell us what kinds of data you are driving / wanting to print? So that we can try to repeat the problem that is presented and thus give you an answer?

By the way (x2), because the == 1 has a trim () and the others do not?

    
answered by 31.01.2018 / 00:08
source