Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'order clause'. #47

Closed
rylanb opened this issue Jul 30, 2015 · 5 comments

Comments

@rylanb
Copy link

rylanb commented Jul 30, 2015

Hello,
I think this is something to do with how I've set this up, but I have the latest version from master (0.8.2 as best I can tell?) and am getting this error.

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'order clause'.

I'm trying to use the search by proximity feature: https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Search-by-Proximity

This is my lookup and the rest of the code looks the same.
{% set entries = craft.entries.section('storeLocations').level(2).map(params).order('map_distance asc') %}
{% set entries = craft.entries.section('storeLocations').level(2).map(params).order('distance asc') %}
{% set entries = craft.entries.section('storeLocations').map(params).order('map_distance asc') %}
{% set entries = craft.entries.section('storeLocations').map(params).order('distance asc') %}

  {{ craft.googleMaps.map(options) }}

  <ul class="search-results">
  {% for entry in entries %}
      <li>
          <h4><a href="{{ entry.url }}">{{ entry.title }}</a></h4>

          {{ craft.googleMaps.data('map', entry.googleMapField) }}

          {% for marker in entry.googleMapField.markers() %}

              <p>
                  <b>{{ marker.title }} - {{ marker.distance }}</b> <br>
              </p>

          {% endfor %}
      </li>
  {% endfor %}

I've read all through the docs, but maybe missed something. This commit seems to indicate there should be a distance field or ability to set that, but I'm confused what that means and if its some sort of setup process I missed? 77a5ff8 ?

Thanks for any help at all. I'm stumped!

@rylanb
Copy link
Author

rylanb commented Jul 30, 2015

Damnit! "Note, when you want to sort by the proximity you must use the following format yourMapField_distance. When the query is built, the field name is prepended to the distance column."

Too late a night writing code. Nvm me.

@rylanb rylanb closed this as completed Jul 30, 2015
@rylanb rylanb reopened this Jul 30, 2015
@rylanb
Copy link
Author

rylanb commented Jul 30, 2015

Well, "Column not found: 1054 Unknown column 'googleMapField_distance' in 'order clause". What am I doing wrong then? I prepended and no dice...

{% set entries = craft.entries.section('storeLocations').level(2).map(params).order('googleMapField_distance asc') %}

googleMapField is the handle for the Google Map I added to the Store Location fields which go in the Store Locations section. I'm stumped. Its late.

@kblizeck
Copy link

I'm getting the same error - any updates here?

Column not found: 1054 Unknown column 'distance' in 'order clause'.

Also doesn't work if I append my googleMap field to distance ::
Column not found: 1054 Unknown column 'googleMap_distance' in 'order clause'.

@mdxprograms
Copy link

I have found a fix for distance. Hopefully this helps someone down the road. I originally used zip codes in comparison and was unable to get distance to work. Even after attempting to use street addresses and cities I was still unsuccessful. However, when I used lat/lng for both addresses it worked like a charm.
I used the geocode function to get the lat/lng from zipcodes and then did the proximity example to get the distance associated between two endpoints.

@objectivehtml
Copy link
Owner

Sorry for the lack of replies guy. Was off work most of last year due to some serious health and personal issues. I'll try to address the problems here in case people are still wondering or having issues.

First off, I changed some code in the last major release and didn't update the wiki so that's likely causing confusing. Now, distance is the default value that is used, and there is a parameter to override. No more should you use the mapField_distance value. This format is obsolete at this point.

Here is another thread where I posted some additional remarks and possible fixes. Im going to close this thread, but if anyone else has any questions related to this issue please feel free to post them here.

#48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants