I have four database tables
locality table: localityid, locality.
jobtype table: typeid, type.
applywork table: id, userid, applyfor applicationsent, jobtypeid, vacancyseenon companyname, doorno buildingname, street, localityid, postcode, telephone, website, email, notes
users: id, role, name, surname, gender, username, password.
I have a page to edit selected field from applywork. I made two dropdowns, one of them used to display the localities and the other one is to display the job types. in these two dropdowns shows all localities and job types but my problem is how to display the locality and jobtype saved in applywork table first if the user didn't change the job type and locality but if the user wish to change it, select other localities and jobtype from same dropdowns. if it is possible anyone help me to make it?
This is my code using form to make an update(the id of user and applywork are get from another page) exsuse me if the indentation is not good:
<?php
require("../headerloggedin.php");
?>
<div id="content">
<?php
if(!empty($_GET["editid"]) && !empty($_GET["edituserid"]))
{
$applyid = $_GET["editid"];
$idofuser = $_GET["edituserid"];
$query = "SELECT * FROM applywork WHERE id = $applyid AND userid = $idofuser";
$resultset = $db->query($query);
while($row = mysql_fetch_array($resultset))
{
?>
<form method="post" name="vacancies" action="updateapplication.php">
<input type="hidden" name="editid" value="<?php echo $applyid;?>"/>
<input type="hidden" name="idofuser" value="<?php echo $idofuser;?>"/>
<table>
<tr>
<td>Vacancy:</td>
<td><input type="text" name="applyfor" value="<?php echo $row["applyfor"]; ?>" /></td>
</tr>
<tr>
<td>Vacancy seen on:</td>
<td><input type="text" name="vacancyseenon" value="<?php echo $row["vacancyseenon"]; ?>" /></td>
</tr>
<tr>
<td>Application sent on:</td>
<td><input type="text" name="applicationsent" value="<?php echo $row["applicationsent"]; ?>" /></td>
</tr>
<tr>
<td>Company Name:</td>
<td><input type="text" name="companyname" value="<?php echo $row["companyname"]; ?>" /></td>
</tr>
<tr>
<td>Door Number:</td>
<td><input type="text" name="doorno" value="<?php echo $row["doorno"]; ?>" /></td>
</tr>
<tr>
<td>Building Name:</td>
<td><input type="text" name="building" value="<?php echo $row["buildingname"]; ?>" /></td>
</tr>
<tr>
<td>Street:</td>
<td><input type="text" name="street" value="<?php echo $row["street"]; ?>" /></td>
</tr>
<tr>
<td>Postcode:</td>
<td><input type="text" name="postcode" value="<?php echo $row["postcode"]; ?>" /></td>
</tr>
<tr>
<td>Telephone:</td>
<td><input type="text" name="telephone" value="<?php echo $row["telephone"]; ?>" /></td>
</tr>
<tr>
<td>Website:</td>
<td><input type="text" name="website" value="<?php echo $row["website"]; ?>" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" value="<?php echo $row["email"]; ?>" /></td>
</tr>
<tr>
<td>Notes:</td>
<td><textarea cols="40" rows="5" name="notes" value="notes" ><?php echo $row["notes"]; ?></textarea></td>
</tr>
<tr>
<td>Job type:</td>
<td>
<select name="typeid">
<?php
$query = "SELECT * FROM jobtype";
$resultset = $db->query($query);
while ($row = mysql_fetch_array($resultset))
{
?>
<option value="<?php echo $row["typeid"]; ?>"><?php echo $row["type"] ?></option>
<?php }
?>
</select>
<br />
</td>
</tr>
<tr>
<td>Locality:</td>
<td>
<select name="localityid">
<?php
$query = "SELECT * FROM locality";
$result = $db->query($query);
while ($row = mysql_fetch_array($result))
{
?>
<option value="<?php echo $row['localityid'];?>"><?php echo $row['locality']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Edit Details" /></td>
</tr>
</table>
</form>
<?php
}
}
?>
<br />
<a href="editapplication.php">Go to main menu.</a>
</div>
<?php require("../footerloggedin.php"); ?>