回发时记住PHP中选定下拉列表位置的最简单方法

回发时记住PHP中选定下拉列表位置的最简单方法,php,drop-down-menu,foreach,postback,smarty,Php,Drop Down Menu,Foreach,Postback,Smarty,注意:我被迫使用TPL文件。我看过这个网站上的其他解决方案,它们似乎不适合我。我知道我想通过使用$\u POST['book']选择什么选项。 我已经尝试过{html_options}(smarty),但似乎没有任何效果。我想做的就是当用户点击submit(GO)按钮时记住下拉列表的位置。实现这一点最简单的方法是什么 <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $book = $_POST['book'];

注意:我被迫使用TPL文件。我看过这个网站上的其他解决方案,它们似乎不适合我。我知道我想通过使用$\u POST['book']选择什么选项。 我已经尝试过{html_options}(smarty),但似乎没有任何效果。我想做的就是当用户点击submit(GO)按钮时记住下拉列表的位置。实现这一点最简单的方法是什么

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
      $book = $_POST['book'];
      $chapter = $_POST['chapter'];
      $tbl_link = "PLD_LINK";

      $query_chapter = "SELECT `TITLE`,`SORT_ORD`, `DESCRIPTION` FROM $tbl_link WHERE `TITLE` LIKE '%$book%' && `SORT_ORD` = '$chapter'";
      $search_chapter=$db->query($query_chapter);
      while($row = $search_chapter->fetch(PDO::FETCH_ASSOC)) {
      { $coal[] = $row; }
      $tpl->assign('coal', $coal);                       
                                                             }
      $search_chapter->closeCursor();
    }
?>
<?php
while($rows = $result->fetch(PDO::FETCH_ASSOC)) {
{ $results[] = $rows ; }
$tpl->assign('results', $results);
}
?>

编辑模板文件

<select name='book'>
{foreach item=rows from=$results}
<option value='{$rows.TITLE}'{if isset($book) && $rows.TITLE == $book} selected{/if}>{$rows.TITLE}</option>{/foreach}
</select>
<select name='book'>
{foreach item=rows from=$results}
<option value='{$rows.TITLE}'{if isset($book) && $rows.TITLE == $book} selected{/if}>{$rows.TITLE}</option>{/foreach}
</select>
$tpl->assign("book", $book);