Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php和mysql查询中使用select标记和a href_Php_Html_Sql_Select_Hyperlink - Fatal编程技术网

在php和mysql查询中使用select标记和a href

在php和mysql查询中使用select标记和a href,php,html,sql,select,hyperlink,Php,Html,Sql,Select,Hyperlink,现在,我有一个php代码,我想用它来创建选择菜单。选择菜单中有用户名,我想在每个选项中添加一个href值。问题是,用户名是一个mysql查询。下面的代码不太有效。更正:它不会添加会话用户id,而是添加列表上最后一个用户名的用户id值,而不管我选择了谁 <?php echo "<select>"; $user_list = mysql_query("SELECT user_id, username FROM users"); while($run_user = mysql_f

现在,我有一个php代码,我想用它来创建选择菜单。选择菜单中有用户名,我想在每个选项中添加一个href值。问题是,用户名是一个mysql查询。下面的代码不太有效。更正:它不会添加会话用户id,而是添加列表上最后一个用户名的用户id值,而不管我选择了谁

<?php

echo "<select>";

$user_list = mysql_query("SELECT user_id, username FROM users");
while($run_user = mysql_fetch_array($user_list)) {
        $user = $run_user['user_id'];
        $username = $run_user['username'];

        echo "<option><a href='index.php?user=$user'>$username<br></a>";    

}

     ?> 
     </option> 
       </select>

在while循环中移动
标记。虽然我不明白你为什么想要一个下拉列表中的链接,或者知道它是否被允许。也许你想要这样的东西:
$username


另外,从PHP5.5.0开始,mysql扩展已被弃用,将来将被删除。相反,应该使用MySQLi或PDO_MySQL扩展。

这似乎不太正确-
中的两个变量都是纯粹从SQL数据库设置的,因此如果数据库是正确的,您应该得到不同的值。添加
用户id
是什么意思?在您的表单提交后,是否将其添加到数据库?@andrewsi抱歉,我很快发现,它为列表中的每个用户名提供了与选项菜单中最后一个人相同的值。另外-为什么您有一个带有href链接的
标记?“我不确定那会起作用。@andrewsi它不起作用。”。我试图找出如何让每个用户都有不同的价值。例如,当您选择“user1”时,超链接将显示“index.php?user=1”。