Right now, I have a php code that I want to make select menu with. In select menu are usernames, and I am wanting to add a href value to each of the options. The problem is, that the usernames are a mysql query. The following code doesn't quite work. CORRECTION: It doesn't add the Session user_id, rather it adds the user_id value of the last user_name on the list, regardless of who I chose.
<?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>
Move the </option>
tag within the while loop. Although I don't understand why you would want a link within a dropdown or know if its allowed. Maybe you wanted something like: <option value=$user_id>$username</option>
Also the mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.