gpt4 book ai didi

PHP 单选按钮获取两个值

转载 作者:行者123 更新时间:2023-11-29 06:38:51 25 4
gpt4 key购买 nike

所以下面的代码从用户选择的行中获取 server_id。但是,我想知道是否有可能从行中获取 server_id 和 server_name 而无需用户做比他已经做的更多的事情(选择一个单选按钮并按下提交)。感谢您的帮助。

<form method="post" name="server_information" id="server_information" action="test.php">
<label>Server Information</label><br><br>
<table border='1'>
<tr>
<th>Selection</th>
<th>User Name</th>
<th>Date Created</th>
<th>Server Name</th>
<th>Server Id</th>
<th>Public DNS</th>
<th>Server Status</th>
</tr>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><input type="radio" name="server" value="<?php echo $row['serverId']; ?>" /></td>
<td><?php echo $row['userName']; ?></td>
<td><?php echo $row['dateCreated']; ?></td>
<td><?php echo $row['serverName']; ?>"</td>
<td><?php echo $row['serverId']; ?></td>
<td><?php echo $row['publicDNS'] ?></td>
<td><?php echo $row['serverStatus']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<br>
<?php endif; ?>

<input type="submit" name="server_stop" value="Stop Server"/>
<input type="submit" name="server_terminate" value="Terminate Server"/>
</form>

最佳答案

您可以在单选值中放置管道 | 或任何其他字符来连接两者,然后在管道上展开 $_POST['server'] ,您将在索引 0 中获得 id 和索引 1 中的名称。

<td><input type="radio" name="server" value="<?php echo $row['serverId'].'|'.$row['serverName']; ?>" /></td>

另一个解决方案是添加一个隐藏的输入并用服务器 ID 命名它,如下所示:

<td>
<input type="radio" name="server" value="<?php echo $row['serverId']; ?>" />
<input type="hidden" name="name_<?php echo $row['serverId'];?>" value="<?php echo $row['serverName'];?>" />
</td>

然后在 PHP 中

  $server_id=(int)$_POST['server'];
$server_name=$_POST['name_'.$server_id];

关于PHP 单选按钮获取两个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22823576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com