concept1483166
concept1483166

Reputation: 39

Populating list box values with sql + html

I am trying to make a drop down list that is populated by a sql database. The sql call is populating the list, but when I try to get the value= part it just doesn't work right.

I want its value= to be the location_id then what is displayed to the user to be the location_description. However, when I do the code below, the value= is the location_description and what is displayed to the user is the location_id. If i reverse the order, it doesn't help.

<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>

The result is:

 <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>

But I need it to be the reverse.

Upvotes: 0

Views: 395

Answers (3)

NoobEditor
NoobEditor

Reputation: 15871

As per w3schools documentation ORDER BY keyword sorts the records in ascending order by default

Simply to reverse, add ORDER BY location_description DESC

Upvotes: 0

Adrian Cornwell
Adrian Cornwell

Reputation: 196

does this work ?

<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>

I just reversed the fields in the SELECT list

Upvotes: 1

Snorre
Snorre

Reputation: 954

Looks good to me. I would suspect there to either be:

  • The table actually contains the description in the location_id column
  • caching problems in either the web server or the browser.

Try restarting your web server and clearing your web cache in your browser.

Upvotes: 0

Related Questions