HTML数据集通过选项传递值
问题描述:
我正在使用带有选择列表的HTML属性数据集。HTML数据集通过选项传递值
<input type="text" name="productcode[]" id="productcode" class="productcode" list="products">
<datalist id="products">
<?php
$query=mysql_query("
SELECT * FROM dbProducts ORDER BY product_name");
while($entry=mysql_fetch_array($query))
{
echo '<option value="' . $entry['product_code']'">' . $entry['product_name'] . '</option>';
} ?>
</datalist>
正如您所见,选项值与显示的文本不同。如果我使用<select>
,我可以将值传递给表单,但只显示我想要的文本。有没有办法与<datalist>
这样做?此刻,我的表单使用product_code和product_name值返回输入类型。
答
你试过吗?
<?php
$query=mysql_query("
SELECT * FROM dbProducts ORDER BY product_name");
while($entry=mysql_fetch_array($query))
{
$productcode = $entry['product_code'];
$productname = $entry['product_name'];
echo "<option value=$productcode>$productname</option>";
}
?>
当您在php中编写html时,您不能在echo中使用“”。
谢谢,这个问题不是与MySQL的查询 - 一切正常。问题是使用数据列表的方式与选择输入相同,并显示一个字符串,但使表单发布单独的值 – tomantford 2014-10-03 12:45:21