How to put value in select

Asked

Viewed 42 times

0

My select is like this:

Nome do carro:<br>
<input type="text" name="nomeCarro" value="<?php echo $dados['nome']; ?>"><br>
Marca:<br>
<select name="marcas">
  <option value="Toyota">Toyota</option>
  <option value="Volkswagen">Volkswagen</option>
  <option value="Bmw">Bmw</option>
  <option value="Honda">Honda</option>
  <option value="Ford">Ford</option>
  <option value="Hyundai">Hyundai</option>
</select>

Ano:<br>
<input type="numeric" name="ano" value="<?php echo $dados['ano']; ?>"><br>
<br><br>
<input type="submit" value="Atualizar">

The question is: How do I bring the value of select, since I brought from others as well.

Só aparece 'Toyota' no select, mesmo sendo outra marca

  • You can explain better what’s not working?

  • and as you brought from others?

1 answer

0

Suppose you should have a table just for allocate tag values.

I believe you already use related tables. Then you must have saved only the brand ID in the table where you are searching for these values, so you must create a method to return the name according to the ID.

[]s.

<select name='marcas'>
   <?php
       foreach($dados['marcas'] as $value)
       {
          echo '<option value="'.$value.'">'.Retornar::nomeMarca($value).'</option>;
       }
   ?>
</select>

Browser other questions tagged

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