Echo'd values in dropdowns

Hi experts, I have come here before asking for assistance in this scheduling application that I am creating and received great help. I have run into an issue recently and cannot figure out how to fix it. I am attempting to make an update screen for my application, where users can select a date and crew and echo the submitted schedule. This IS working. The issue comes in that I am echoing names into dropdowns as the first value, where the names are already existing. This is causing that name to appear once as echod, and again in the dropdown.

Is there a way I can select a name based off the echo'd value?

// Start the session
<!DOCTYPE html>
					<meta charset="utf-8">
					<meta name="viewport" content="width=device-width, initial-scale=1">
					<link rel="stylesheet" href="">
					<script src=""></script>
					<script src=""></script>
div.container {	background-color:#ffffb3;length: 250%;margin-right: 100px;width: 300%;}
div.submitbutton {position:relative; left:700px;}
									<div class="container">
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$strID = null;
$result = array();
	$serverName = "XX";
	$userName = "";
	$userPassword = '';
	$dbName = "IS_DGMC";
$strID = isset($ID) ? $ID : false;
$strCREW = isset($_SESSION["CREW"]) ? $_SESSION["CREW"] : false;
if ($strID && $strCREW) {
 	$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  if( $conn === false ) {
    die( print_r( sqlsrv_errors(), true));
  $params = array($strID, $strCREW);
$query = sqlsrv_query( $conn, $stmt, $params);
if (!$query) trigger_error( sqlsrv_errors(), E_USER_WARNING); 

<form id="commonClassForThreeSelects" name="commonClassForThreeSelects" method="post" action= "iframe2_save.php">
<table width="300" border="1" id="commonClassForThreeSelects">
    <th width="91"> <div align="center">Area</div></th>
    <th width="20PX"> <div align="center">Person1</div></th>
    <th width="91"> <div align="center">Person2</div></th>
    <th width="91"> <div align="center">Person3</div></th>
    <th width="91"> <div align="center">Person4</div></th>
    <th width="91"> <div align="center">Person5</div></th>
    <th width="91"> <div align="center">Person6</div></th>
    <th width="91"> <div align="center">Person7</div></th>
    <th width="91"> <div align="center">Person8</div></th>


while($result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC))

	<!--<td align="center"  height="50" width="120PX" nowrap> <?php if ($result["DATE"]!= NULL ){echo $result["DATE"] ->format("Y-m-d") ;}?></td>-->
$selectedname2[0] = $result['PERSON1'];
$selectedname2[1] = $result['PERSON2'];
$selectedname2[2] = $result['PERSON3'];
$selectedname2[3] =$result['PERSON4'];
$selectedname2[4] =$result['PERSON5'];
$selectedname2[5] =$result['PERSON6'];

  echo "<tr>";
echo "<input type='hidden' name='CREW_".$k."' value='$result[CREW]'/>"; 
echo "<input type='hidden' name='SHIFT_".$k."' value='$result[SHIFT]'/>"; 

echo"<td>";echo "<input type='text' name='AREA".$k."' style='width:120px' value='$result[AREA]'/>"; ECHO"</td>";

	for ($a=0; $a<8; $a++){

	echo"<td>";echo"<select  name='PACKER_".$k."_".$a."'/>";

			$location_query = "select distinct NAME from XX.dbo.CE_EMPLOYEES_CREW_A where POSITION = 'GENERAL' order by NAME";
			$locationQ = sqlsrv_query( $conn, $location_query );
			if( $locationQ === false) {
				die( print_r( sqlsrv_errors(), true) );
            $Lines[0] = '';
				echo "<option value='$selectedname2[$a]'>$selectedname2[$a]</option>";
			while( $row = sqlsrv_fetch_array( $locationQ, SQLSRV_FETCH_ASSOC) ) {
					if($row['NAME'] != $selectedname[$a]);
						echo "<option value='".$row['NAME']."'>".$row['NAME']."</option>";			

                  $Lines[$p] = $row['NAME'];
			$numLines = sizeof($Lines);

<div class="submitbutton">
<input type="submit" style="height:30px; width:200px" value="submit" id="#q5">
var $selects = $('select');
    $('select').change(function () {
        $('option:hidden', $selects).each(function () {
            var self = this,
                toShow = true;
            $selects.not($(this).parent()).each(function () {
                if (self.value == this.value) toShow = false;
            if (toShow) $(this).show();
        if (this.value != 0) //to keep default option available
          $selects.not(this).children('option[value=' + this.value + ']').hide();


Open in new window

Thankyou so much for any help provided.
peter OjedaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Trying to understand the issue here. I tried out a version of your code (adapted so that it will work here) - not sure what I am looking for though. The code itself has some issues that need to be addressed - for instance

The SESSION variables don't make sense - assigning a date to an ID field is confusing and you have this on lines 25-25

Open in new window

And then this on lines 39 and 40
$strID = isset($ID) ? $ID : false;
$strCREW = isset($_SESSION["CREW"]) ? $_SESSION["CREW"] : false;

Open in new window

- What is the $CREW variable for
- where is SESSION set
- what is this page supposed to do

Here is my version of it

How must I change my data to see the problem and what am I looking for?
peter OjedaAuthor Commented:
Hi Julien thankyou for your input I am still relatively new to a lot of things so I am sure a lot of my code is either unnecessary or not in the best practice. The session variables on line 25 are coming from the previous page. I am passing these variables into  $ID and $CREW, and am then passing those into strings which is passed into the $params (line 54) for the select query. I am attemping to make a scheduling program, where users can go back and modify a schedule that is set on a previous day. After the select statement I am attempting to echo the names from my sql database into the dropdowns as selected. So if "Bob" is echo'd into the dropdown, Bob will appear selected.
Julian HansenCommented:
Ok but if you look at my sample you will see that is what is happening - I need to know what needs to be done extra / differently from what is being done in my adapted sample.
Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

peter OjedaAuthor Commented:
Hi sorry for the delay yes the function to not be able to select the same name twice is exactly what I was looking for. But if you see in my code I am echoing a name from my sqldb. I have attached some images below. As you can see, the name "Bishop, La" is being echo'd from my db schedule table. The rest of the value of the dropdown are being echo'd from my db table Employee_Names. If possible, I want to just have the employee name selected based off the value echo'd from the schedule db.
Julian HansenCommented:
Looking at your second image I am still not seeing the problem - it looks like the selected person "Bishop, La" is in the drop down once - what am I missing? In a drop down the selected item is shown in the list and the drop down which is what I am seeing in the image.

Can you give me some of your data so I can replicate the issue. I need just enough examples of data in the two tables to reproduce the problem.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peter OjedaAuthor Commented:
Hi Julien I'm sorry but I'm going to have to close the question. I found many more issues in my program that I need to fix first. I will come back to this question sometime in the future.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.