Jump to content

[SOLVED] Getting PHP to ammended the selected in option field


nvee

Recommended Posts

Hey Guys

 

thanks for everyones help so far. This site and its users are oozing awesomness.

 

I am busy with a php script for editing users, of which 1 field is the TITLE of the person (mrs, miss, ms) and it is displayed as a dropdown box. I have written the code which allows you to get the values in the fields for the rest of the fields, but I am not sure how to get PHP to change the actual selected dropdown box. The only thing I can think of is to have a if else statement for each option in the select dropdown, but I assume that when someone has a lot of options in their SELECT dropdown, it will be a lot of work and I am sure someone knows the trick behind this :)

 

Any suggestions?

Hey Wayne

 

Thanks for your reply. I think you may have misunderstood me and reading my own post, i probably left out some important info. Navigation starts with a page called student.php which then gives you a list of students. Once you click on their name, it opens a new page called student_info.php which looks like the student registration form, but obviously this time just with the student values already entered into the form for quick editing. I have managed to already get all of the other forms right (and have gotten the dropdown right) but the dropdown way I am taking to me would appear to be alot of unneccesary work, but hey ... IT WORKS :) I was actually merely wondering if anyone else had a better way of getting this to work.

 

Here is my code:

 

<select name="title" value="<?php echo "$title"; ?>" id="title">
                                <?php 
								if ($result["title"] = "Mr.") {
                                  echo "<option value=\"Mr.\" selected=\"selected\">Mr.</option>";
								} else {
							echo "<option value=\"Mr.\">Mr.</option>";
								}
							if ($result["title"] = "Mrs.") {
                                  echo "<option value=\"Mrs.\" selected=\"selected\">Mrs.</option>";
								} else {
							echo "<option value=\"Mrs.\">Mrs.</option>";
								}
							if ($result["title"] = "Miss") {
                                  echo "<option value=\"Miss\" selected=\"selected\">Miss</option>";
								} else {
							echo "<option value=\"Miss\">Miss</option>";
								}	
							?>
                                </select>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.