How do I display results from a database into an i

2019-03-06 23:11发布

问题:

            <?php
                $i = 0;
                while ($row = $res->fetchRow()) {
                    $i++;
                    echo '<tr>';
                    echo '<td><input value='{$row['moduleCode']}' />  </td>';
                    echo '</tr>';
                }
                ?>

As you can see in my php code i have tried echoing the results from the database into the input area via the 'value', however this keeps coming up with a syntax error? can someone show me where I have gone wrong?

回答1:

Use double-quoted strings if you want variables to be parsed within :

echo "<td><input value='{$row['moduleCode']}' />  </td>";

or extract your variables :

echo '<td><input value="'.$row['moduleCode'].'" />  </td>';