php - Assigning variable value in dropdown list in table -
i have list of materials drop down in each row of table (100 rows). want selectively assign row selected material.
for example, suppose $materialoptions assigned array (1=>'material 1', 2=>'material 2',3=>'material 3'). list of dropdown in each row.
i want assign in php say, in row 20, material selected 'material 2'.
below implementation. not able assign properly. html/smarty code
<form name='materialsel' id='materialsel' method='post' action=''> <table> {section name=counter start=1 loop=100 step=1}   <tr>     <td><select name="materialid_{$smarty.section.counter.index}" id="materialid_{$smarty.section.counter.index}" onchange='return document.forms.materialsel.submit();'><option value='0'>select material</option>  {html_options selected=$material_$smarty.section.counter.index options=$materialoptions}    </select>       </td>  </tr> {/section}  </table>  </form>   php code
$smarty->assign("materialoptions", array (1=>'material 1', 2=>'material 2',3=>'material 3'));   //in row 20, material selected 'material 2'
$smarty->assign("material_20",2); //not able      
you should change in template file
{html_options selected=$material_$smarty.section.counter.index options=$materialoptions}   into
{html_options selected=${"material_{$smarty.section.counter.index}"} options=$materialoptions}   but in case should defined material_1, material_2 , on variables because use them option creation
** edit **
you haven't mentioned need in smarty 2. smarty 2 doesn't support variable variables should rethink of using other way achieve this.
in php instead of
$smarty->assign("material_20",2);   you should assign variables way:
$selections = array( '20' => 2);         $smarty->assign("selections", $selections);   and in template file should change
{html_options selected=$material_$smarty.section.counter.index options=$materialoptions}   into
{html_options selected=$selections[$smarty.section.counter.index] options=$materialoptions}      
Comments
Post a Comment