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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
clockwatcherConnect With a Mentor Commented:
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
 
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
 
TehJiBueyAuthor Commented:
thanx very much!!
0
All Courses

From novice to tech pro — start learning today.