PHP/MySQL 下拉列表有多列,语法有问题
我正在尝试获取一个下拉列表来显示表中的多个列,并将所选行的主 ID 存储在变量名称中。
如果我删除 CONCAT 函数并选择一列,我会得到一个行列表,但我不知道如何选择多个列。我做错了什么?
<li>
<?php
$sql="SELECT CONCAT(county, ' ',municipality, ' ',park), id FROM mtmg.locality";
$result=mysql_query($sql, $connection);
echo '<label for="county_municipality_park">County, Municipality, Park</label>';
echo '<select id="county_municipality_park" name="county_municipality_park">';
while ($row = mysql_fetch_assoc($result)) {echo '<option value="'.$row['county,municipality,park'].'">'.$row['county,municipality,park'].'</option>';}
echo mysql_error();
echo '</select>';
?>
</li>
I'm trying to get a drop down list to display multiple columns from a table, and for the selected row's primary id to be stored in the variable name.
I get a list of rows if I drop the CONCAT function and SELECT a single column, but I can't figure out how to select more than one. What am I doing wrong?
<li>
<?php
$sql="SELECT CONCAT(county, ' ',municipality, ' ',park), id FROM mtmg.locality";
$result=mysql_query($sql, $connection);
echo '<label for="county_municipality_park">County, Municipality, Park</label>';
echo '<select id="county_municipality_park" name="county_municipality_park">';
while ($row = mysql_fetch_assoc($result)) {echo '<option value="'.$row['county,municipality,park'].'">'.$row['county,municipality,park'].'</option>';}
echo mysql_error();
echo '</select>';
?>
</li>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要为 CONCAT() 函数指定一个别名,例如
,然后在
$row
数组中引用它,即$row['county_municipality_park']
。You need to give your CONCAT() function an alias, something like
and then reference it as such in the
$row
array, i.e.$row['county_municipality_park']
.尝试这个
,然后使用
$row['location']
try this
and then use
$row['location']