How to show an array coming from the database in an input

2

<input type="text" class="form-control" name="lanches" id="lanches" value="<?php echo $resultado['lanches']; ?>" >

I have this input above where it receives this array that is inside the database

How do I ...

    
asked by anonymous 02.12.2018 / 02:28

3 answers

2

You can use the foreach , in your case I understood that it would be showing the value in your correct input?

The foreach structure is

foreach($array as $linha){

}

It will perform an iteration (just like the for structure), for each line of your Array, and in each iteration you will perform the manipulation with the $ line variable.

For example, if you had this array: $ array = ["pos1", "pos2", "pos3"], foreach would run 3 times, and at each iteration the value being accessed would be used by the variable after the "as" in the example above the variable $ line.

In case of your code it would look something like this:

foreach($array as $valor){
    <input type="text" class="form-control" name="lanches" id="lanches" value=" <?php echo $valor; ?>" >
}
    
02.12.2018 / 02:46
1

You can use a foreach. It would look something like this:

    foreach($resultado['lanche'] as $id){ 
echo "<input type='text' class='form-control' name='lanches[$id]' id='lanches_$id' value='$id'>";
}
    
02.12.2018 / 02:49
0

Good night, use the foreach. documentation: link

    
02.12.2018 / 02:36