PHP variable in an HTML value

Asked

Viewed 9,874 times

0

How do I put the php variable in the next value:

<?php
    while($ver=mysql_fetch_row($busca)){ 
        $id1 = $ver[0];
?>
        <tr>
            <td><input type="radio" value="$id1"></td>
            <td><?php echo "$ver[0]"; ?></td>
    # code ...

The way I did value="$id1" didn’t work. Only one of the "radios" should be selected, so the values should be different:

inserir a descrição da imagem aqui

2 answers

4

Use the php tag <?php echo $id1; ?> or <?=$id1?> (if php short tags is enabled)

ex:

<input type="radio" value="<?php echo $id1; ?>">
  • short tags makes life easier !

  • 3

    If the PHP version is 5.4 >= no need to enable shortags. It is native

  • Right, but it didn’t solve my problem, I have a table with database values contained in an array, which are shown from the loop of repetition, and I want to make you select only one of the options, for that the values must be different:

  • @Eduardo, yes, that kind of clarification has to be within of your question.

  • @Eduardobalestrin this kind of information already escapes the scope of your question. New question should be asked about this, mainly informing your sql structure so that we can help you.

  • Okay okay, thank you

Show 1 more comment

0

In the first <td> you didn’t put the tags of PHP.
In the following <td> you did but this using an array and the string interpreter tries to capture only the var in such a way that I understand the index [0] as string and not index.

Solving

<input type="radio" value="<?php echo $id1; ?>"> // var direto
ou
<input type="radio" value="<?php echo $var[0]; ?>"> // var direto
ou
<input type="radio" value="<?php echo "{$var[0]}"; ?>"> // {} para indicar inicio e fim de var, inclui o index [0]

Browser other questions tagged

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