I am using PHP to populate my options for a dropdown menu in HTML via Javascript append. It works so far, and I am using a conditional statement to only show the value for that team ID if the session variable is set. The issue is i need to display all the dropdown options (like the else/while statement in PHP) even when the session variable is set so people can still have that option to manually select another ID, but if session is set auto select the value that the session variable is set to.... otherwise just display the options selecting default option (1) like in my else statement. Any suggestion on how I should go about this? Thanks!
HTML
<td class="label_container">Team ID#</td>
<td class="input_container">
<select id="prepping_team" name="prepping_team"></select>
</td>
JS
//Populate Team IDs
function get_prepping_team() {
$.ajax({
url: './php/getprepping_team.php',
success: function(data) {
$('#prepping_team').append(data);
}
});
};
PHP
//Grab Session (if set)
session_start();
$_SESSION['prepping_team'];
$prep_team = $_POST['prepping_team'];
header("Cache-Control: no-cache, must-revalidate");
header('Access-Control-Allow-Origin: *');
header('Content-type: multipart/form-data');
$logAuditFile = "../log/prepform.log";
$logModule = "getprepping_team.php";
include '/mnt/library/auditlog.php';
require("/mnt/library/configdb.php");
include '/mnt/library/accessdb.php';
//Parse and store the db ini file, this will return an associative array
db_config_cables_test();
db_connect();
$sql = mysql_query("SELECT pt_id FROM preppingteam;");
//IF SESISON VARIALBE IS SET
if(isset($_SESSION['prepping_team'])) {
print "<option value=\"".$_SESSION['prepping_team']."\">".$_SESSION['prepping_team']."</option>";
//print "<option value=\"".$_SESSION['prepping_team']."\">".$_SESSION['prepping_team']."</option>";
//OTHERWISE LOAD TEAM IDs
} else {
while ($data = mysql_fetch_assoc($sql)) {
print "<option value=\"".$data['pt_id']."\">".$data['pt_id']."</option>";
}
}