Jump to content

inserting blank value in a drop-down ...


rsammy

Recommended Posts

I have some fields on my screen which are drop-down boxes. right now, i either have them default to the very first on the list or a selected value. i need to do it slightly different. i need to insert a blank value in the drop down and make it the default and then display the list from the database.

heres my code ...

<tr>
  <td width="275"> <div align="right"><font class="inputLbl">Preferred Provider:&nbsp;&nbsp;</font></div></td>
  <td colspan="2"> <?PHP
        $query="select phy_id, phy_fname, phy_lname from phy_det where phy_disabled = 'Enable' order by phy_lname, phy_fname";
       
        $result= mysql_query ($query);
        if ($result)
        {
        print ("<select name='physician'>");
            if ($row = mysql_fetch_array($result))
{
    do
    {
            print("<option value=\"");
print $row["phy_id"];
if($pat_phy_id == $row["phy_id"])
{
    print("\" selected>");
}
else
{
    print("\">");
}
  print $row["phy_lname"]; print (", "); print $row["phy_fname"];
  print("</option>");
  }
  while($row = mysql_fetch_array($result));
  }
}
print ("</select>");
        ?>
  </td>
</tr>

now, how do i insert a blank in the drop down before filling it with values obtained from the query?

help please... thanx in advance!
Link to comment
Share on other sites

If i understand you right, then this is what you want:

[code]<?php
$query="select phy_id, phy_fname, phy_lname from phy_det where phy_disabled = 'Enable' order by phy_lname, phy_fname";
$result = mysql_query ($query);
if ($result) {
echo "<select name='physician'>\n";
echo "<option value=\"\">Select one</option>\n";
while($row = mysql_fetch_array($result)) {
    if($pat_phy_id == $row["phy_id"]) {
        echo '<option selected value="'.$row["phy_id"].'">'.$row["phy_lname"].', '.$row["phy_fname"].'</option>';
    }
      else {
          echo '<option value="'.$row["phy_id"].'">'.$row["phy_lname"].', '.$row["phy_fname"].'</option>';
        }
    }
    echo "</select>";
}
?>[/code]
Link to comment
Share on other sites

i really appreciate ur help haaglin!

i need somemore help tho...
now I am stuck with this one! this seems to be a pretty straight forward one, but I am not able to go ahead with this one either. I need to do the same here too... insert a blank in the drop down and default it to the blank on pageload.


<tr>
  <td width="196"> <div align="right"><font class="inputLbl">Location:&nbsp;&nbsp;</font></div></td>
  <td colspan="2">
    <?PHP
$querys="SELECT org_ID, org_name FROM orgs where org_type !='Office' order by org_name ASC";
$results= mysql_query ($querys);
if ($results)
{

print ("<select name='location'>");
if ($row= mysql_fetch_array($results))
{
do
{
  print ("<option value=\"");
  print $row["org_ID"];
  print ("\">");
  print $row["org_name"];
  print ("</option>");
}
while ($row = mysql_fetch_array($results));
}
}
print ("</select>");
    ?>
  </td>
</tr>

help please?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.