如何从下拉列表中选择用户名作为URL的var

时间:2013-02-27 01:44:56

标签: php html

如何让所选变量显示在来自的URL中  <select> ...

我的代码是:

print "<select name=\"assignedby\" multiple size=\"10\">";

while ($data = dbResult($qh)) {
        print "<option name=\"$data[name]\"";
        print ">$data[name]</option>\n";
}
print "</select>";
print "<br><a href='".$_SERVER['PHP_SELF']."?action=add'>Add</a> || <a href='".$_SERVER['PHP_SELF']."?origname=$data[name]'>Edit</a>\n";

当有人点击“编辑”链接时,其显示为:http://www.site.com?origname= 我希望它从下拉列表中显示实际选择的origname ... 喜欢: http://www.site.com?origname= $ selecteduser-fromdroplist

请帮忙!

1 个答案:

答案 0 :(得分:1)

为什么不用表格method = get?

<form id="select_name" action="" method="get">
    <select name="origname">
    <?php while ($data = dbResult($qh)): ?>
        <option value="<?php echo $data[name]; ?>"><?php echo $data[name]; ?></option>
    <?php endwhile; ?>
    </select>
    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=add">Add</a> || <input type="submit" name="submit" value="Edit">
</form>

但至于为什么你的代码不起作用,你在while循环之外调用$ data [name']项。