Sorting Field Dropdown

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 29, 2013   (RSS)

I am setting up a dropdown with the following settings:

Get options from database (advanced)

Section Tablename: yachts
Options values: num
Option labels: yacht_name

How do I get the dropdown list to be sorted alphabetically? I assume I need to use "Get options from MySQL query" instead.

I just need some guidance on correct syntax. Is it something like this?

SELECT num, yacht_name
FROM `<?php echo $TABLE_PREFIX?>yachts`
SORT BY yacht_name ASC

Im getting "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY yacht_name' at line 3"

Many thanks,

Hi,

You're very close! I think you need to use order by instead:

SELECT num, yacht_name
FROM `<?php echo $TABLE_PREFIX?>yachts`
ORDER BY yacht_name ASC

ORDER BY is the statement that is used to decide which column should be used to sort results, and if the results should be ascending or descending.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com