–EDITED TO BETTER DESCRIBE THE SCENARIO–
I have a MySQL database containing 2 tables, technicians and work_orders. The technicians table has columns techID, tech_surname, tech_firstname and tech_userlogin. The work_orders table has columnsjobID (PK), wtechID, wtech_surname, wtech_firstname and wtech_userlogin among other things.
I have a page with a repeat region listing submitted work orders, the date of the work order is a link that passes the jobID in a URL to a page containing an update form. The form is populated with data taken from the work_orders table particular the the jobID (customer name, address, equip to repair, problem, etc.). On the form is a dropdown populated from the technicians table. This dropdown lists the tech_userlogin of the technicians. I have included hidden fields to the form page, wtech_userlogin and wtechID.
When I view the source of the page it shows the values from the work_orders table, but I don’t know how to work it into the query to accomplish the desired results.
When the form posts it updates the work_orders table. All of this is working.
What I am hoping to accomplish is to have the wtech_userlogin (from the work_orders table) for the particular work order become the default value of the dropdown menu if a technician has already been selected. If no selection has previously been made from the dropdown menu I would like the default of the dropdown to be “–Select Technician–“. I’ve tried a few things but nothing works so far.
Here is the code for the dropdown:
<select name="tech_userlogin" id="tech_userlogin">
<?php
$sql="SELECT techID, tech_userlogin FROM technicians";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$techID=$row["techID"];
$tech_userlogin=$row["tech_userlogin"];
$options.="<option value=\"$tech_userlogin\">$tech_userlogin</option>";
}
if(empty($tech_userlogin)) {
die ('You must select a Technician');
}
?>
<option value='<?php echo $options; ?>' selected='selected'>""<?php echo $options; ?>
</select>
Can anyone help me with this problem? Any assistance will be appreciated. I’m very new at PHP and MySQL. I’m taking a course in web design and we use Dreamweaver. I want to break away from Dreamweaver and learn how to do this without the wizards. I’ve been able to get my forms to post and all of my insert, update and delete functions work from things I’ve been able to cobble together from the internet, but this one really has me stumped.
Cheers.
Something like this is what you want: