php - How to get data from the database and display it in a combobox in html -
<tr> <td>subject:</td> <td> <select name="subject"> <option value="<?php echo $subject;?>"></option> </select> </td> </tr> <?php $connection = mysqli_connect("localhost", "root", "", "phobiamming") or die (mysqli_error()); $sql = "select * section"; $result = mysqli_query($connection, $sql); while ($row= mysqli_fetch_array($result)) { echo $row['subject']; } $connection->close(); ?> i can't display data db combobox. don't know if code right.
<tr> <td>subject:</td> <td><select name="subject"> <option value="subject"><?php $connection = mysqli_connect("localhost", "root", "", "phobiamming") or die (mysqli_error()); // sql query $strsql = "select * sections"; // execute query (the recordset $rs contains result) $rs = mysqli_query($connection, $strsql); // loop recordset $rs // each row made array ($row) using mysql_fetch_array while($row = mysqli_fetch_array($rs)) { // write value of column firstname (which in array $row) echo $row['subject']. "<br>"; } // close database connection $connection->close(); ?></option> </select></td> </tr> this updated code, can display data db problem rows in db display, can't create line break
put option value in while loop
<tr> <td>subject:</td> <td> <select name="subject"> <?php $connection = mysqli_connect("localhost", "root", "", "phobiamming") or die (mysqli_error()); $sql = "select * section"; $result = mysqli_query($connection, $sql); while ($row= mysqli_fetch_array($result)) { ?> <option value="<?php echo $row['$subject']; ?>"><?php echo $row['$subject']; ?></option> <?php } $connection->close(); ?> </select> </td> </tr>
Comments
Post a Comment