im just wondering if there is a way to solve my problem. Right now in my database I have a table called headstonesa that I have searchable. But there is a colum called codes that has 9 letters to it which stands for the cemetery. When you search the table it gives the code in the result. For example WCSTC02RC would show up. I also have another table that has the list of cemeteries in them. Is there any way to make it so that whenever the codes show up it can automatically search the cemeteries table for the code and show the name of the cemetery instead?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Family Search</title>
<style type="text/css">
th {
	color: #900;
	height: 100%;
	border-right-width: 1px;
	border-right-style: solid;
	border-right-color: #666;
	border-left-color: #666;
}
tr {
	height: 100%;
	width: 100%;
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-top-color: #666;
	border-right-color: #666;
	border-bottom-color: #666;
}
</style>
</head>

<body>
<?php
    mysql_connect ("localhost", "root","root") or die (mysql_error());
    mysql_select_db ("FHSNL");
	//sets all values in form to php variables
    $surname = $_POST['surname'];
    $given = $_POST['given'];
	$maiden = $_POST['maiden'];
	$deathdate = $_POST['death'];
	$deathbefore = $_POST['death'] - 5;
	$deathafter = $_POST['death'] + 5;
	$age = $_POST['age'];
	$birth = $_POST['birth'];
	$birthplace = $_POST['birthplace'];
	$deathplace = $_POST['deathplace'];
	$erected = $_POST['erected'];
	$region = $_POST['region'];
	$religion = $_POST['religion'];
	//divides into smaller sql pieces for filled in form input.
	if($surname)$piece[] = "`SURNAME` LIKE '%$surname%'";
	if($given)$piece[] = "`GIVEN` LIKE '%$given%'";
	if($maiden)$piece[] = "`MAIDEN` LIKE '%$maiden%'";
	if($age)$piece[] = "`AGE` LIKE '%$age%'";
	if($deathplace)$piece[] = "`PLACE_OF_DEATH` LIKE '%$deathplace%'";
	if($region)$piece[] = "`TOWN` LIKE '%$region%'";
	if($religion)$piece[] = "`RELIGION` LIKE '%$religion%'";
	if($deathdate)$piece[] = "`YEAR_OF_DEATH` BETWEEN '$deathbefore' AND '$deathafter'";
	//if submit button is pressed it runs the search query.
    if(isset($_POST['submit'])){
		if(isset($piece)){
  $sqlend = implode(" AND ",$piece);
  $sql = mysql_query("SELECT * FROM `HEADSTONESA` WHERE $sqlend");
  $rows = mysql_num_rows($sql);
  //constructs the table.
	echo "<table><tr><th>ID</th><th>Keys</th><th>Plot Number</th><th>Region</th><th>Town</th><th>Religon</th><th>Surname</th><th>Given</th><th>Maiden</th><th>Date of Death</th><th>Age</th><th>Date of Birth</th><th>Place of Birth</th><th>Place of Death</th><th>Erected by</th><th>Additional Information</th>";
	//finds values in tables and puts them into rows.
    for($j = 0; $j < $rows; ++$j)
	{
		$row = mysql_fetch_row($sql);
		echo "<tr>";
		for($k = 0; $k < 15; ++$k) echo "<td>$row[$k]</td>";
		echo "</tr>";
	}
	echo "</table>";
	//if nothing found prints out the following.
    if(!$rows)
    echo "No results where found";
	
    }
}
//if no search terms entered prints the following.
else{
  echo "You must enter valid search terms";
}
    
    
    ?>
    
</body>
</html>

Thanks for the help

Join the two tables before searching. Soething like this;

SELECT cemetaryid, cemetaryname FROM tableA inner join tableB on tableA.cemetaryid = tableB.cemetaryid WHERE tableA.cemetaryid = $requested_id;

where
1. tableA contains name of cemetaries
2. tableB = headstonesa
3. $requested_id is the requested id