savagenoob Posted January 7, 2009 Share Posted January 7, 2009 I have a table in mysql for offices and I want to display all the offices in the table on a drop down box in a form. Its for a login system and they have to specify which office they are in. Here is my wrong code: $office -> $myrow['office']; function createDropdown($arr, $frm) { echo '<select name="'.$frm.'" id="'.$frm.'"><option value="">Select one…</option>'; foreach ($arr as $key => $value) { echo '<option value="'.$value.'">'.$value.'</option>'; } echo '</select>'; } ?> <form action="process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> <tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr> <label for="Office">Office:</label> <?php createDropdown($office, 'office'); ?> <tr><td colspan="2" align="right"> <input type="hidden" name="subjoin" value="1"> <input type="submit" value="Register"></td></tr> <tr><td colspan="2" align="left"><a href="main.php">Back to Main</a></td></tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/139913-solved-array-to-drop-down-form-box-help/ Share on other sites More sharing options...
Brian W Posted January 7, 2009 Share Posted January 7, 2009 whats it do now? like, what is wrong? what is $myrow['office']? (may help if you post your query) Link to comment https://forums.phpfreaks.com/topic/139913-solved-array-to-drop-down-form-box-help/#findComment-732030 Share on other sites More sharing options...
chronister Posted January 8, 2009 Share Posted January 8, 2009 If $arr is a valid array containing the key / value pairs for the offices, then your code should work. You have the right idea, you just need to ensure that the array your looping through is the array that contains the data you wish. Looking at the function again, your calling it right, and passing data to it, so is $office an array with all the information you wish to use in the form? Nate Link to comment https://forums.phpfreaks.com/topic/139913-solved-array-to-drop-down-form-box-help/#findComment-732113 Share on other sites More sharing options...
savagenoob Posted January 8, 2009 Author Share Posted January 8, 2009 Yep, $office pulls all the entries in the Office table... Link to comment https://forums.phpfreaks.com/topic/139913-solved-array-to-drop-down-form-box-help/#findComment-732283 Share on other sites More sharing options...
chronister Posted January 8, 2009 Share Posted January 8, 2009 Well then what do you get when you do print_r($office); This should tell you if that array is actually an array or not. nate Link to comment https://forums.phpfreaks.com/topic/139913-solved-array-to-drop-down-form-box-help/#findComment-732294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.