CGI using perl & html

When I retrieve data from the database for the user to view, there is a field which is a dropdown option box.
Therefore, how to have that particular option selected when the data are fetched from the database and being stored in an array.
TehJiBueyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xabiCommented:
<select name="foo">
..
..
<option value="anything" selected>option1<(option>
..
..
</select>

xabi
0
TehJiBueyAuthor Commented:
$sqlstr = "select Name, Phone, Pager, Designation_c, Photo from staff ";
$sqlstr.="where UserID = '$info[0]'";

print "$sqlstr";
$sth = $dbh->prepare($sqlstr) || die $dbh->errstr;
$sth->execute() || die $sth->errstr;

print "<table border=1>";
print qq(<form method="post" action="/cgi-bin/hansen/staff/staEditUpdate.cgi">);
while (@des = $sth->fetchrow_array)
{
        print qq(<tr><th>Name</th>
        <input type=hidden name=UserID value="$info[0]">
        <td><input type="text" name="name" value="$des[0]" size=40></td></tr>
        <tr><th>Phone</th>
        <td><input type="text" name="phone" value="$des[1]" size=10></td></tr>
        <tr><th>Pager</th>
        <td><input type="text" name="pager" value="$des[2]" size=10></td></tr>
<tr><th>Designation Code</th>
        <td><select name=designation_c>);

$sqlstr = "select Designation_c from Designation";
$ath = $dbh->prepare($sqlstr) || die $dbh->errstr;
$ath->execute() || die $ath->errstr;
        while ($c = $ath->fetchrow_array)
        {
                if ($c == $des[3])
                {
                        print "<option value=$des[3] selected>$des[3]</option>";
                }
                else
                {
                        print "<option value=$c>$c</option>";
                }
        }
        print "</select></td>";
        print qq(<tr><th>Photo</th>
        <td><input type="text" name="photo" value="$des[4]" size=50></td></tr></
table>
        <br><br><input type="Submit" value="Update"></form>);

ok the above is what i currently have.
isn't that correct? i can't get the correct output that i want. pls help.
0
clockwatcherCommented:
I'm guessing you're comparing strings-- So, I'd think you'd want to be using 'eq' ;-)
               
     if ($c eq $des[3])  {
          print "<option value=$des[3] selected>$des[3]</option>";
     }
     else  {
          print "<option value=$c>$c</option>";
     }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TehJiBueyAuthor Commented:
thanx very much!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.