如何显示所选值表格下拉列表?

时间:2015-12-29 06:00:53

标签: php html

我有一个列表代理。一旦我选择并保存它,我想显示所选数据。我怎么能这样做?。我想在选定的列表中显示它,一旦我重新加载或返回到该页面

<?php
include_once("../noaccess.php"); 
include_once(CLASS_PATH."fetch_service.php"); 
$objfetch = new fetchService();
include_once(CLASS_PATH."proxy.php");
$objproxy = new Proxy();
include_once(CLASS_PATH."log.php"); 
$objlog= new changelog();
$account_id=$_SESSION['account_id'];
global $mysqli;
if($_POST['submit']=="Save")
{
    $pname=$_POST['proxy'];
    $query="UPDATE `proxy` SET `proxy_default`='1' where `proxyname`='$pname'";
    $mysqli->query($query) or die($mysqli->error);
    $_SESSION['check_update'] = "1";
    setcookie("msg","Proxy Seleted",time()+5,"/");
    header("location:".SITE_URL."index.php?view=default_proxy");
}
?>

<form name="frmcr" id="frmcr" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" id="mode" value="insert" />
<table align="left" id="tblworking_hours" class="tbl_altcolor shadow" style="width:25%;margin-left:30px">
   <thead>
      <tr>
         <th align="center"><b>Proxy</b></th>
         <td><select name="proxy" id="proxy" class="required input">
               <option value="">Select</option>
               <!--              <option value="<?php echo $i ;?>"<?php echo $i==$ring21 ? "selected":"";?> ><?php echo $i;?></option> -->

               <?php
                    $result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' ");
                          foreach($result as $key=>$resrproxy)
                          {
                          ?>
               <option value="<?php echo $resrproxy['proxyname'];?>"<?php echo $resrproxy['proxyname']== $resrproxy['proxyname'] ? "selected":"";?>><?php echo $resrproxy['proxyname'];?></option>
               <?php } ?>
            </select></td>
      </tr>
      <tr>
         <td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Save" class="btn" style="margin-left:35px;"/></td>
      </tr>
   </thead>
</table>
</div>

2 个答案:

答案 0 :(得分:0)

您需要将$resrproxy['proxyname']值与$pname进行比较。你的代码应该是这样的:

// your code

<select name="proxy" id="proxy" class="required input">
    <option value="">Select</option>

    <?php
        $result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' ");
        foreach($result as $key=>$resrproxy){
            $option = "<option value=\"{$resrproxy['proxyname']}\"";
            if(isset($pname)){
                if($pname == $resrproxy['proxyname']){
                    $option .= " selected=\"selected\"";
                }
            }
            $option .= ">{$resrproxy['proxyname']}</option>";
            echo $option;
        } 
    ?>
</select> 

// your code   `   

答案 1 :(得分:0)

  <td>
  <select name="proxy" id="proxy" class="required input">
  <option value="">Select</option>

  <?php
  $result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' and `proxy_default`='1'");
  $pname=$result[0]['proxyname'];

  $result = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."' ");
  foreach($result as $key=>$resrproxy)
  {
  ?>
  <option value="<?php echo $resrproxy['proxyname'];?>"<?php echo $resrproxy['proxyname']==$pname ? "selected":"";?>><?php echo $resrproxy['proxyname'];?></option>
  <?php } ?>
</select>
  </td>