php - how to make drop down list item selected in database -


i have mysql table 40 items in it. want reference 40 items in form on webpage drop down list. instead of writing out 40 items following know if item has been selected:

<!doctype html> <html> </head> <body> <select> <option value="health & beauty"<?php if (isset($_post['sitetype']) && ($_post['sitetype'] == 'health & beauty')) echo ' selected="selected"'; ?>>health & beauty</option></select> </body> </html> , on 40 times... 

i wondering how instead using sql statement following: here have far.

$sql = "select * sitetypes"; $f = mysqli_query($dbc, $sql) or trigger_error("query: $sql\n<br />mysqli error: " . mysqli_error($dbc)); while($row2 = mysqli_fetch_array($f, mysqli_assoc)){ echo '<option value="' . $row2['sitetypeid'] . '">' . $row2['sitetype'] . '</option><\select>'; } 

the code above produces nice drop down list, don't know how make database know when item selected user. code write make happen? can use sql statement option or have write each item out wrote @ beginning of post.

this might you

add select attribute table of type varchar

alter table user add selected varchar(255) 

give them values '0'

and in html page

<select name="sitename">     <option></option>     <!-- options --> </select> 

and when form submitted use this

echo $_post['sitename']; 

then use query database know user selected field in usertable or want

update user set selcted='$_post["sitename"]' userid='currectuserid' 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -