Platon_82
Новичок
Помогите написать функцию для смарти
Есть у меня функция для вывода данных в селект по умолчанию:
Вызываю ее в шаблоне так: {selection}
Теперь мне нужно выводить этот же селект, где известно выбранную запись(то что выбрал пользователь)
Пробовал так:
Вызываю ее в шаблоне так: {selection id=12}, но грузится селект как в первой функции. Без выбранного елемента..(((
Как сделать правильно?
Есть у меня функция для вывода данных в селект по умолчанию:
PHP:
function selection()
{
$sql="select * from table order by id";
$res=db_select($sql);
while ($item = mysql_fetch_array($res))
{
$txt .= '<option value="'.$item['id'].'">'.$item['text'].'</option>';
}
return $txt;
}
$smarty->register_function("selection", "selection");
Теперь мне нужно выводить этот же селект, где известно выбранную запись(то что выбрал пользователь)
Пробовал так:
PHP:
function selection($id)
{
$sql="select * from table order by id";
$res=db_select($sql);
while ($item = mysql_fetch_array($res))
{
if($id==$item['id'])
$txt .= '<option value="'.$item['id'].'" selected=\"selected\">'.$item['text'].'</option>';
else
$txt .= '<option value="'.$item['id'].'">'.$item['text'].'</option>';
}
return $txt;
}
$smarty->register_function("selection", "selection");
Как сделать правильно?