2

如何使过滤后的选择仍然出现在请求之后。

因此,如果我有选项 1、2 和 3。当我选择 2 并显示数据时,我仍然希望显示 2,表示数据已通过选项 2 过滤。

echo "<form name='country_list' method='POST' action='http://opben.com/colombia/familias-de-carteras' >";
echo "<select name='Country' tabindex='1' >";

while($row = mysql_fetch_array($result))
 {
  echo " <option  value='". $row['Fund_Manager_Company_Code'] ."'>". $row['Fund_Manager_Company_Name'] ."</option>";
 }
echo "</select>";
echo "<input type='submit' value='Filter' />";
echo "</form>";
4

4 回答 4

3

你可以这样做:

    $country = isset($_POST['Country']) ? $_POST['Country'] : '';
    while($row = mysql_fetch_array($result))
     {
      echo " <option  value='". $row['Fund_Manager_Company_Code'] ."' ".(($row['Fund_Manager_Company_Code'] == $country) ? 'selected="selected"' : '').">". $row['Fund_Manager_Company_Name'] ."</option>";
     }
于 2013-02-26T20:37:12.720 回答
2

您需要将 selected 属性添加到选项:

$Country = $_POST['Country'];
$sected = 'selected = "selected" ';
while($row = mysql_fetch_array($result))
 {
    echo " <option  ".($row['Fund_Manager_Company_Code'] == $Country? $selected : '')."value='". $row['Fund_Manager_Company_Code'] ."'>". $row['Fund_Manager_Company_Name'] ."</option>";
}

然后将选择该值选择并发布的那个...

于 2013-02-26T20:37:08.333 回答
0

就像是

echo" <option  value='" . $row['Fund_Manager_Company_Code'] . "' " . ((isset($_POST['Country']) && $_POST['Country'] == $row['Fund_Manager_Company_Code'])
? 'selected="selected"' : '') . ">" . $row['Fund_Manager_Company_Name'] . "</option>";
于 2013-02-26T20:38:15.393 回答
0

提交后,您需要在 PHP 代码中捕获选择:

$selection = $_POST['Country'];

echo "<form name='country_list' method='POST' action='http://opben.com/colombia/familias-de-carteras' >";
echo "<select name='Country' tabindex='1' >";

while($row = mysql_fetch_array($result))
 {
  $selected = "";
  if ($row['Fund_Manager_Company_Code'] == $selection) {
    $selected = "selected";
  }
  echo " <option  value='". $row['Fund_Manager_Company_Code'] ."' ".$selected.">". $row['Fund_Manager_Company_Name'] ."</option>";
 }
echo "</select>";
echo "<input type='submit' value='Filter' />";
echo "</form>";
于 2013-02-26T20:38:53.797 回答