I've been searching on the site (and through Google) but I guess I might be misphrasing my problem.
Here's my situation. I have this dynamically populated dropdown (which is working) that can, in some occasions, receive a value to display a specific option.
echo "<td><select id='bids_id' class='ui-widget-content ui-corner-all normalselect' style='width: 150px'>";
$sql = "SELECT
`bids`.`id`,
`bids`.`name`
FROM
`bids`
Inner Join `bids_primes` ON `bids`.`id` = `bids_primes`.`bid_id`
WHERE
`bids_primes`.`tid` = '". $db->real_escape_string($_SESSION['Current_TID']) ."'
";
$querybids = $db->query($sql);
while($row = $querybids->fetch_object()) {
echo "<option value='{$row->id}' ". ($row->id == $timeinfo->relatedbid ? "selected=selected" : "") .">{$row->name}</option>";
}
Now the only thing I'm trying to do, with no luck, is to add a "hardcoded" choice with the values of '0' and a text of 'Other'. This choice should also be bound by the same mechanic (where it can be specified to be pre-selected).
[UPDATE] So to help out with the context of my situation, here is the code that preceeds this part. This is a PHP file that is called from within another PHP file (same principal as a div). The PHP in question is an entry form that is used both for new data entry and modification of existing data (and this interacts with the database).
The script knows if it's adding or modifying based on the "entry_id" it receives as paramater, a bit like a function would.
if(isset($_REQUEST['entry']) && ($_REQUEST['entry'] > 0)) {
$sql = "SELECT
`cap_plan`.`entryid`,
`cap_plan`.`startdate`,
`bids`.`name`,
`cap_plan`.`duration`,
`cap_plan`.`description`,
`cap_plan`.`relatedbid`
FROM
`cap_plan`
LEFT JOIN
`bids` ON `cap_plan`.`relatedbid` = `bids`.`id`
WHERE
`cap_plan`.`entryid` = '". $db->real_escape_string($_REQUEST['entry']) ."'
";
$timeinfo = $db->query($sql)->fetch_object();
}
else {
$timeinfo = new StdClass();
$timeinfo->entryid = 0;
$timeinfo->employee = $_SESSION['name'];
$timeinfo->startdate = date("Y-m-d");
$timeinfo->duration = "";
$timeinfo->description = "";
$timeinfo->relatedbid = "0";
}
Here's a screenshot to help illustrate it all: https://i.stack.imgur.com/C7d5d.png
If I understand your question correctly, all you wish to do is to insert a hard-coded option at the top of the list, BEFORE the dynamically generated choices.
Just do this:
Note that you do not need to specify the selected attribute on the first, default, option tag (the "Choose One" option), because it will automatically be the selected option IF nothing else is selected. I believe that is what you would want.
What I would do, though, is to assign all values to a variable and then echo out the variable, so that everything appears all-at-once. Like this: