我试图用我所有的货币创造一个下跌,目前的价值是1,2和3。我需要下跌的价值保持为数字,但希望选项文本表示英镑,欧元和美元代替。我有这样的代码:
<select class='dc_input' name='currency' id ='currency'>
<?php
$sql="SELECT l.currency
FROM locations l
GROUP BY l.currency";
$sites = mysql_query($sql);
while ($row = mysql_fetch_assoc($sites)) {
echo '<option value="' .$row['currency']. '"' .$selected. '> </option>';
}
?>
</select>这很管用,我只是不知道该怎么做才能改变每个人的生活。
发布于 2013-07-29 14:47:42
<?php
$currencies = array('', 'GBP', 'EUR', 'USD');
?>
<select class='dc_input' name='currency' id ='currency'>
<?php
$sql="SELECT l.currency
FROM locations l
GROUP BY l.currency";
$sites = mysql_query($sql);
while ($row = mysql_fetch_assoc($sites)) {
$index = $row['currency'];
echo '<option value="' .$index. '"' .$selected. '> '.$currencies[$index].' </option>';
}
?>
</select>此外,您还可以在数据库中存储货币ID和货币名称。如果你开始支持超过3种货币,这将更容易对你。
发布于 2013-07-29 14:43:27
你不能从你的数据库中选择号码。完成之后,将文本放在开始/结束标记之间,并将数字值保留在value属性中。
echo '<option value="', htmlspecialchars($row['id']), '">',
htmlspecialchars($row['currency']), '</option>';https://stackoverflow.com/questions/17926914
复制相似问题