php 从同一行获取2个值并放置在不同的变量上[重复]

siv3szwd  于 2023-03-21  发布在  PHP
关注(0)|答案(1)|浏览(90)

此问题在此处已有答案

Acquiring multiple values from one select option value. PHP HTML(3个答案)
How to post two values in an option field?(6个答案)
How can i send two values from the same select option to a url in php?(2个答案)
how to give multiple values to a select-option tag?(5个答案)
Pass Multiple Values In HTML Option Tag Via PHP(1个答案)
昨天关门了。
我的表中有4列

SUGAR_ID    
LEVEL   
VALUE   
VOLUME

我想从选择一行中同时获取水平和体积,该怎么做?

$query = "SELECT * FROM sugarlevel order by SUGAR_ID asc";
$result = mysqli_query($db, $query) or die ("Bad SQL: $query");

$sugaa = "<select class='btn btn-success' name='sugarlevel' required>
<option disabled selected hidden>Sugar Level</option>";
while ($row = mysqli_fetch_assoc($result)) {

$sugaa .= "<option value='".$row['LEVEL']."'>".$row['LEVEL']."</option>";
}
$sugaa .= "</select>";
n6lpvg4x

n6lpvg4x1#

一个简单的方法是设置:

$sugaa .= '<option value=" . $row['LEVEL'] . '|' . $row['VOLUME'] . /* ... */

我已经用了'|'作为分隔符,您可以选择最适合您的
然后,一旦接收到值:

[$level, $value] = explode('|', $_POST['sugarlevel']);

显然,这是一个必须改进的例子,特别是出于“安全”的原因

相关问题