...

View Full Version : option Default on pull-down menu



jlhamma
03-08-2010, 09:34 PM
Trying to show a default (or current value) to the first line of a pull down option. Value will only show if I refresh the page. In the example below, the default value is in the line:

echo "<option value={$row['code']}></option>";

Not sure if this is where the problem lies. The pull does show the value but like I said only after refreshing the page.



$query = "SELECT * FROM wos WHERE disciplineID=1 AND woID='{$getwoID}'";
if (!($result = @mysql_query ($query, $connection)))
die("die 3");

$row = @ mysql_fetch_array($result);

echo "<p>WO Number: <b>{$row['woID']}</b></p>";
echo "<p>Equipment : <b>{$row['equipmentID']}</b></p>";

// problem code field
require './includes/dbConnection.inc';
if (!($connection = @ mysql_connect($db_host, $db_user, $db_pass)))
die("Could not connect to sql");

if (!mysql_select_db($db_name, $connection))
die("Could not connect to database!");

$query_code = "SELECT * FROM troublecodes WHERE PG=1 ORDER BY code ASC";
?>
<label for="code" class="required">Select Trouble Code: </label>&nbsp;
<select name='code' id='code' width="200">

<?php $result_code = mysql_query($query_code);
echo "<option value={$row['code']}></option>";
while ($line = mysql_fetch_array($result_code)) {
echo "<option value='".$line['code']."'>" .$line['code']. " - ".$line['description']."</option>";
}

angst
03-08-2010, 09:59 PM
$result_code = mysql_query($query_code);
while ($line = mysql_fetch_array($result_code)) {
if($row['code'] == $line['code']){
echo "<option value='".$line['code']."' SELECTED>" .$line['code']. " - ".$line['description']."</option>";
} else {
echo "<option value='".$line['code']."'>" .$line['code']. " - ".$line['description']."</option>";
}
}

jlhamma
03-08-2010, 10:21 PM
Thank you very much! That did it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum