CodeIgniter Forums
Sorting results into categories for Select dropdown - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Sorting results into categories for Select dropdown (/showthread.php?tid=60554)



Sorting results into categories for Select dropdown - El Forum - 04-21-2014

[eluser]Andy UK[/eluser]
Good evening all,

I currently have a dropdown select with cities in alphabetical order. Some are from one country and some are from another. I would now like to separate these cities into categories, the category being the country.

With a simple activerecord join I can add the country name to the result set for each city, but I don't know if there's a way to use this to categorise the results. Is this possible or will I have to first loop through the countries and query the database for each country to get the active cities and then store in a multiple array by country? I'm guessing the second, but if anyone knows an easier way, I'm interested in hearing it!

Thanks


Sorting results into categories for Select dropdown - El Forum - 04-21-2014

[eluser]CroNiX[/eluser]
If you have a lot of options it might be better to separate it into 2 dropdown. When the first dropdown (country) is selected, it populates the 2nd dropdown with the cities from that country.