php - Foreign Key in web forms -
i creating web forms users enter data database. thinking of way enter/choose foreign keys. example have table has 1:n relation table b. want create form table b. user can enter normal information in input boxes. enter foreign key thought dropdown list, entries of table displayed. unfortuanately, dropdown list of html can display 1 coulmn. cannot display id , name of picked entry.
does know smart way display name of entry pass id?
now doing this. here id of picked entry displayed user. want display name, pass id.
<select name="input_modul"> <?php $sql = "select id, name tablea;"; if($result = $con->query($sql)) { $rows = $result->num_rows; while($row = $result->fetch_array()) { echo "<option>". $row['id'] . "</option>"; } } ?> </select>
quite pass $row['id']
value
-attriubute of option
-element
echo "<option value=\"" . $row['id'] . "\">" . $row['name'] . "</option>";
this way, value of $row['name']
displayed value in list, while $row['id']
passed along stuff (get / post / others)
Comments
Post a Comment