troubleshooting Question

Echo'd values in dropdowns

Avatar of peter Ojeda
peter Ojeda asked on
PHPJavaScript
6 Comments2 Solutions169 ViewsLast Modified:
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?

<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
					<html>
					<head>
					<meta charset="utf-8">
					<meta name="viewport" content="width=device-width, initial-scale=1">
					<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
					<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
					<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
div.container {	background-color:#ffffb3;length: 250%;margin-right: 100px;width: 300%;}
div.submitbutton {position:relative; left:700px;}
									</style>
									</head>
									<body>
									<div class="container">
<article> 
<?php
//$_SESSION['DATE'];
//$_SESSION['CREW'];
		$ID= $_SESSION["DATE"];
		$CREW=$_SESSION["CREW"];
		//$ID=$_GET["ID"];
		//$CREW=$_GET["CREW"];
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$strID = null;
// DEFAULT RETURN
$result = array();
	$serverName = "XX";
	$userName = "";
	$userPassword = '';
	$dbName = "IS_DGMC";
// GET PARAMS SAFELY
$strID = isset($ID) ? $ID : false;
$strCREW = isset($_SESSION["CREW"]) ? $_SESSION["CREW"] : false;
// ONLY PROCEED IF WE GOT VALID PARAMETERS
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));
  }
  // SET UP QUERY WITH PARAMETERS
// I THINK THIS MAY BE CLOSER TO WHAT YOU WANT
$stmt = "SELECT * FROM [CE_MANNING_PG2] WHERE [DATE] = ? AND [CREW]= ?
";
  
  // ADD PARAMETER VALUES
  $params = array($strID, $strCREW);
  
$query = sqlsrv_query( $conn, $stmt, $params);
if (!$query) trigger_error( sqlsrv_errors(), E_USER_WARNING); 
  

}
// RETURN DATA
?>
<form id="commonClassForThreeSelects" name="commonClassForThreeSelects" method="post" action= "iframe2_save.php">
<table width="300" border="1" id="commonClassForThreeSelects">
  <tr>
    <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>



  </tr>

<?php
$k=0;
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>-->
<?php
$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) );
			}
			$p=0;
            $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'];
                $p++;
		}}}
			$numLines = sizeof($Lines);
			sqlsrv_free_stmt($locationQ);
	echo"</select>";
  ECHO"</tr>";
  
?>
<?php
$k++;
}
  ECHO"</TABLE>";
?>

<div class="submitbutton">
<input type="submit" style="height:30px; width:200px" value="submit" id="#q5">
</div>
</form>
<?php
sqlsrv_close($conn);
?>
</div>
</article>
<script>
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();
    });
</script>

</body>
</html>
Thankyou so much for any help provided.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros