我正在尝试创建一个由sql数据库填充的下拉列表。 sql调用正在填充列表,但是当我尝试获取value = part时,它只是无法正常工作。
我希望它的value =是location_id,然后显示给用户的是location_description。但是,当我执行下面的代码时,value =是location_description,向用户显示的是location_id。如果我颠倒了订单,它就无济于事。
<select name="building" id="building">
~[tlist_sql;SELECT DISTINCT location_description, location_id FROM u_locations ORDER BY location_description]
<option value="~(location_id)" >~(location_description)</option>
[/tlist_sql]
</select>
结果是:
<select name="building" id="building">
<option value="ADAM">1</option>
<option value="ADMIN">0</option>
<option value="BRON">12</option>
<option value="CLA">3</option>
<option value="CLATT">15</option>
<option value="COQ">18</option>
<option value="DAR">19</option>
</select>
但我需要反过来。
答案 0 :(得分:1)
这有用吗?
<select name="building" id="building">
~[tlist_sql;SELECT DISTINCT location_id,location_description FROM u_locations ORDER BY location_description]
<option value="~(location_id)" >~(location_description)</option>
[/tlist_sql]
</select>
我刚刚翻转了SELECT列表中的字段
答案 1 :(得分:0)
对我来说很好看。我怀疑要么是:
尝试重新启动网络服务器并在浏览器中清除网络缓存。
答案 2 :(得分:0)
根据w3schools documentation ORDER BY
关键字,默认情况下按ascending
顺序排序记录
只需反向,添加ORDER BY location_description DESC