Gilmore Posted December 1, 2006 Share Posted December 1, 2006 I'm trying to update a CMS that someone made for me ages ago by adding a 'member type' field in the 'members' table.I've managed to build in the new field and you can enter the memberType number manually (1 to 3) in the admin section.The Member Types are:1 = Manager2 = Supervisor3 = Floor ManagerAnd the input box looks like this:[code]<input name="memberType" type="text" id="memberType" value="<? echo $_POST['memberType'] ?>">[/code]At the moment I enter the number manually, but I'd rather do it with a jump menu. [code]<select name="select"> <option value="3">Floor Manager</option> <option value="2">Supervisor</option> <option value="1">Manager</option> </select>[/code]I would like for the person using the CMS to see the memberType and when they select a type, it writes the relating number to the database.Does that makes sense?I'd appreciate any help. TIA. Quote Link to comment https://forums.phpfreaks.com/topic/29093-jump-menu-options-to-write-to-database/ Share on other sites More sharing options...
HuggieBear Posted December 1, 2006 Share Posted December 1, 2006 I'd create a separate table in my database called memberTypes, it has two columns, the first is called id, is unique, and is auto incrementing and the second is called type.Insert the rows into it1 Manager2 Supervisor3 Floor ManagerThen on your page, you want to generate the dropdown menu like this:[code]<?php// Print the start of the select codeecho "<select name=\"type\" id=\"type\">\n";// Query the database for values$sql = "SELECT * FROM memberTypes";$types = mysql_query($sql) or die ("Can't execute: $sql<br>\n<br>\n" . mysql_error());// Output a row for each field in the databasewhile ($row = mysql_fetch_array($types, MYSQL_ASSOC)){ echo "<option value=\"{$row['id']}\">{$row['type']}</option>\n";}// Print the end of the select codeecho "</select>\n";?>[/code]This way, you can add as many rows as you like to the memberTypes table, in case you need to create new types in the future and they'll appear in the page without having to re-write any php.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/29093-jump-menu-options-to-write-to-database/#findComment-133346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.