Q:

How to select an option at page load time?

{if  isset($smarty.get.insert) && $smarty.get.insert == "GeneralQuestions"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=1 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "sponsor"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=2 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "partner"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=3 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "speaker"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=4 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "press"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=5 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "group"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=6 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "newsletter"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=7 }
            {else if  isset($smarty.get.insert) && $smarty.get.insert == "international"}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected=8 }
            {else}
            {html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray  }
            {/if}

and my sql is:
 $contactTitleArray['0']='- Please Select -';
    while($row = mysql_fetch_array( $result )) 
    {
        $contactTitleArray[$row['cTitle']]=$row['cTitle'];
    } 
    return $contactTitleArray;

It's not select any option at page load time.
It display all the content in that array. But not select any option.
Thanks in advance.

A:

The problem is that in selected you cannot place in that case numerical index but you need to put key from your table. As your keys are the same as value: $row['cTitle'] you need to use one of those values.
For instance you have the following PHP data:
$modData['contactTitleArray']['0']='- Please Select -';
$modData['contactTitleArray']['a']='a';
$modData['contactTitleArray']['b']='b';
$modData['contactTitleArray']['caa']='c';
$modData['contactTitleArray']['daa']='d';
$modData['contactTitleArray']['e']='e';
$modData['contactTitleArray']['f']='f';
$modData['contactTitleArray']['g']='g';
$smarty->assign('modData',$modData);

If you want to select option with visible value c you need to use caa key as selected as below:
{html_options  style="width:93%;" name=moreinfo id=moreinfo options=$modData.contactTitleArray selected="caa" }

