Can someone please help with code on how to use a computed cck field to return the closest zipcode (just one result) to a location latitude and longitude. I have tried several ways but keep getting NULL. My computed field is called computed_zipcode and I am storing it as an INT with a data lenght of 7. Working with databases is way over my head.
Thank you in advance;
Paul
Comments
Comment #1
pwieck commentedComment #2
pwieck commentedPlease help. I am stuck on this one.
Comment #3
farald commentedPaulwamail, I believe we are having sort of the same problem. I am trying to count the number of articles of content type dblog in nearest proximity.
So, Ive comed up with this (not entirely perfect) code:
The problem is, exacly as yours, I cannot get an answer from the
$node->locations[0][latitude]OR$node->location[latitude]fields, other than NULL.So, Im pretty much stuck too. If I override the input values with this:
The script outputs fine.
So, what is needed to get the locations lat/lon of node from inside a computed field?
Thanks:)
Comment #4
netbear commentedAnd what is there if you print
in your node template?
Comment #5
farald commentedOh, I see that we are working on different drupal versions. I do not know if the above works for 5.x, but at least maybe you got some clue on how to create your db query:)
Comment #6
farald commentedWill have a look.
Comment #7
farald commentedThis one indicates the use of
$node->location['latitude'], and this one:indicates a
$node->locations[0]['latitude']when only one location.So, this leaves me with no idea why I can't reach the value from computed field.
Maybe find a way of somehow sneaking print_r into a computed field to see what values are present in the field.
Comment #8
netbear commentedmay be this is weights problem and when the computed field is doing its job there is not location data yet. If so you need to set weight of computed field module havier than location module in system table.
Comment #9
farald commentedI have set the weight of locations to -10 at http://mysite.org/admin/content/node-type/dblog.
The computed field is at the very bottom of the list. Still nothing.
Thanks for suggestion though:)
Trying to use a cck location field instead, to see if that works better.
Comment #10
pwieck commentedI should be home Monday Jan 12 and will try to mess with it again. I had given up due to no response. I am working on a lake fishing site and I only have the latitude and longitude locations for the lakes. The weather program I am using and a script I have to find closest cities needs the zipcode. I thought it would be better to have cck compute the zipcode and store it in the database instead of manually looking up and entering over 2000 zipcodes. I am using the HamWeather script for my weather and the people there have been very helpful. They wrote me a query to use my lat and long pairs and search their data in my database for the closest city for the weather program to use. I think I may be able to modify that query to work inside the location zipcode data.
I have not dug that deep into this problem because I thought it would of been a one, two knock out for someone to answer. I have had most all my posts go unanswered here on drupal.
I thank you all for your time and interest.
Paul
Comment #11
pwieck commentedStill no luck
Here is what I tried.
The display format is
$display = $node_field_item['value'];And using
<?php print $node->field_testcomp[0]['value'] ?>to show the resultI get nothing printed back.
Comment #12
farald commentedThat query should indeed do the trick.Have you tried putting in a dummy lat/lon to see if the query works well?
If yes, your problem is identical to mine, $node->locations[0]['latitude'] = NULL, which is quite odd..
I got around the problem for now by accessing the database every time the node is loaded (via content template), so that the value is there. My solution is of course in question when it comes to performance, but it will have to do the job for now.
Comment #13
pwieck commentedI went all the way to the basics and computed field still no show or won't work. I have all up-to-date modules on 5.14 drupal
1. Named field test_hello
2. In the code area I just put
$node_field_item['value'] = 'hello';3. Clicked Display this field
4. In display area put
$display = $node_field_item['value'];5. Tried both store in database with text, length 25, not null, sortable and not using database
6. In contemplate put
<?php print $node->field_test_hello[0]['value'] ?>7. Tried updating old cck node and making new cck node
8. Tried test server and live
Nothing....Goose Egg
Can someone help me. I am at my ends with this. Thanks
Comment #14
farald commentedFinally!
I saved the whole $node query to the database, and found out that location values is indeed not saved in $node->location[0][latitude]. BUT, the new latitudes are stored in following:
So, to manipulate the locations from computed field, use these:)
However, I do not know what other location fields are called. To find out, just put
in your custom field.
Let it save to the db as a 'text' type, save a node, then go to phpmyadmin and inspect the array.