Myths on Maps

  • Log in
  • « New feature
  • display toggling with javascript »

MySQL and group_concat

Posted by gregster on 02 Jun 2010 in Activity log

I have a view called view_places_citatons and it hooks together places and the citations that mention them.
I wanted to be able to provide a list of citations and the places associated with them, like this:
Apollod. Epit..1.13 (Camicus, Icarion Sea)

The idea is that if the user clicks on Apollod. Epit..1.13 they will add all of the places listed in parentheses to the map. However, if they click on an individual place in the parentheses (like Camicus) they'll only add that place to the map.

The MySQL function to use is GROUP_CONCAT:
SELECT `citation`,
GROUP_CONCAT(DISTINCT `place_name` ORDER BY place_name ASC SEPARATOR ', ') AS place_name,
GROUP_CONCAT(DISTINCT CAST(`place_id` AS CHAR(20)) ORDER BY place_name ASC SEPARATOR ', ') AS place_id,
GROUP_CONCAT(DISTINCT CAST(`latitude` AS CHAR(20)) ORDER BY place_name ASC SEPARATOR ', ') AS latitude,
GROUP_CONCAT(DISTINCT CAST(`longitude` AS CHAR(20)) ORDER BY place_name ASC SEPARATOR ', ') AS longitude
FROM `view_places_citations`
WHERE `citation` LIKE '%epit%'
GROUP BY `citation`
ORDER BY `citation`

Int values need to be cast as strings (but make sure you tell MySQL how long your string is {e.g. AS CHAR(20)} or you'll get funny results), because you can't catenate ints. I use the AS to provide a hook in php - the field names seem to get lost in the catenation process. To order my output according to citation I need to include the GROUP BY.

Results from PHPMyAdmin look like this:
Apollod. Epit..1.13 | Camicus, Icarion Sea | 253, 252 | 37.36, 37.72 | 13.88, 26.09

Now, the idea is to take the output and create javascript arrays from it. Clicking the citation will sequentially add places in the array to the map.

This entry was posted by Greg and filed under Activity log.

Myths on Maps

This project will focus on deploying an interactive map of Europe with overlays for Greek and Roman myths, history, people and events.
SVN instructions for MoM editors
Development URL
HCMC Blogs home
  • Archives
  • Categories

Search

XML Feeds

  • Atom: Posts
  • RSS 2.0: Posts
What is RSS?

This collection ©2023 by admin • Help • Forums software