jr8rdt Posted June 15, 2007 Share Posted June 15, 2007 Hello I need to do form input select. the easiest thing would be hardcoding the values. but this is headache to maintain/grow. the smarter and obvious way is to get the select option values from a database? but I am not quite sure how to do that . In addition I have multiple input select in 1 program (hardware, user, sofware, etc). other than using database what are my options? what about flat file or xml? <tr><td>Hardware</td> <td><select name="hw"> <option value="Dual-Core AMD Opteron Processor 8218">Dual-Core AMD Opteron Processor 8218</option> <option value="Proliant DL380">Proliant DL380</option> <option value="Proliant DL585">Proliant DL585</option> </select></td></tr> <tr><td>User</td> <td><select name="user">"; <option value='John'>John</option>"; <option value='Patrick'>Patrick</option>"; <option value='Kevin'>Kevin</option>"; <option value='Jason'>Jason</option>"; <option value='Glen'>Glen</option>"; <option value='Joe'>Joe</option>"; <option value='Dan'>Dan</option>"; <option value='Dennis'>Dennis</opt Link to comment https://forums.phpfreaks.com/topic/55727-form-input-select-from-using-db/ Share on other sites More sharing options...
per1os Posted June 15, 2007 Share Posted June 15, 2007 XML would be a decent way to go. But I think the database would be easier. You would need a table with an id field, a name field (for the name of the select) and a value field which houses the data something like id::value,id2::value2, so you can explode the data and easily parse it out for displaying in an option statement. Link to comment https://forums.phpfreaks.com/topic/55727-form-input-select-from-using-db/#findComment-275347 Share on other sites More sharing options...
widget Posted June 15, 2007 Share Posted June 15, 2007 I have this snippet of code in my site for displaying a select box from the database <select name="avatar_name"> <?php $sql11 = "select * from `avatar_blank` where `user_name` = '$username'"; $query11 = mysql_query($sql11) or die(mysql_error()); while($dd11 = mysql_fetch_array($query11)){ $avatar_name = $dd11['avatar_name']; echo "<option value=\"$avatar_name\">$avatar_name</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/55727-form-input-select-from-using-db/#findComment-275363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.