Getting correct result from database using counter

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Getting correct result from database using counter

Post by SparkOut » Mon Mar 21, 2016 8:40 am

I can't work out for sure what is going on, but one thing I can see is in your addMarker handler you are expecting two parameters. The pPosition is constructed from the latitude and longitude, separated by comma. I wonder if something is fooling the addMarker handler into believing that there are three parameters, and trying to use just the lat as the position and the long as the title.

Also in loadSelectedResult you add 1 to counter, but not the tCounter variable

Bellballer1
Posts: 40
Joined: Sat Oct 24, 2015 5:42 pm

Re: Getting correct result from database using counter

Post by Bellballer1 » Mon Mar 21, 2016 3:48 pm

Hi SparkOut!

Thanks for taking a look. The addMarker handler is doing its job...it is putting the correct values into latitude, longitude, and title (using pPosition and pTitle). Additionally, I changed to "add 1 to tCounter" in "loadSelectedResult" and that did not change the results I am getting.

I continue to think the trouble is in the "getMarkerCode" function, specifically in where the "add 1 to tCounter" and "end repeat" is placed. I changed my database (now "databaseGetMarkerCode") just to make it unique from the other database that gets the address and lat/long in the "loadSelectedResult" handler in the card script. Below is from my google maps api substack.

function getMarkerCode pName
if sMarkers[pName] is empty then
return "error: no such marker."
else

local tMarkerCode, tPlaceJson, tPlaceArray

put databaseGetMarkerCode() into tData ## each line of tData contains the zIndex numerical value. There are 3 lines.
put empty into tLocArray
put 1 into tCounter
set the itemDel to tab

repeat for each line tLine in tData
put item 1 of tLine into tLocArray[tCounter]["zIndex"]

put "var " & pName & " = new google.maps.Marker({" & CR into tMarkerCode
put "icon: 'https://chart.googleapis.com/chart?chst ... tter&chld= " & tLocArray[tCounter]["zIndex"] & "|FE6256|000000|'," & CR after tMarkerCode
put "position: new google.maps.LatLng(" & sMarkers[pName]["pos"] & ")," & CR after tMarkerCode
put "map: map," & CR after tMarkerCode
put "title:'" & sMarkers[pName]["title"] & "'," & CR after tMarkerCode
put "});"& CR after tMarkerCode

put getPlaceByLatLong(sMarkers[pName]["pos"]) into tPlaceJson
put jsonToArray(tPlaceJson) into tPlaceArray
##put tPlaceArray["results"][1]["formatted_address"]
put "(function (marker) {"&CR after tMarkerCode
put "google.maps.event.addListener(marker, 'click', function (e) {"&CR after tMarkerCode
put "infobox.setContent('<div id=" & quote & "infobox" & quote & " >'+'<p>'+" & quote & tPlaceArray["results"][1]["formatted_address"] &quote & "+'</p>'+'</div>');" & CR after tMarkerCode
put "infobox.open(map, marker);"&CR after tMarkerCode
put "markCentered(marker.position);"&CR after tMarkerCode
put "});" & CR after tMarkerCode
put "})(" & pName & ");"&CR after tMarkerCode
add 1 to tCounter
end repeat
end if
return tMarkerCode

end getMarkerCode

I currently have 3 records or lines in my database. Depending on where the "add 1 to tCounter" and "end repeat" lines are located, I get 1 of 2 results...

Result A -- only the results from line 1 of the record is being used...therefore tLocArray[1]["zIndex"] appears in all 3 of the markers. OR

Result B -- only the results from line 3 of the record is being used...therefore tLocArray[3]["zIndex"] appears in all 3 of the markers.

I may have to add more "if/then" statements to get it to work.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Getting correct result from database using counter

Post by phaworth » Mon Mar 21, 2016 8:32 pm

Did you change your SELECT statement? The one you posted had zindex as the 4th item in each data line, not the first.

I can't spot anything wrong with your repeat loop and where you increment the counter, very strange. I'd be willing to take a look at this if you are able to send me your stack, database, and other necessary files to pete@lcsql.com.

Pete

Bellballer1
Posts: 40
Joined: Sat Oct 24, 2015 5:42 pm

Re: Getting correct result from database using counter

Post by Bellballer1 » Mon Mar 21, 2016 9:00 pm

Hi Pete!

I did change the SELECT statement. That part is working correctly.

I will send you everything to the email you provided. I very much appreciate you taking a look!

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Getting correct result from database using counter

Post by AxWald » Tue Mar 22, 2016 1:45 pm

Hi,

just to be sure:
Bellballer1 wrote: repeat for each line tLine in tData
Do you really have proper lines in tData?

Or do you use:

Code: Select all

revDataFromQuery([columnDelim],[rowDelim],databaseID,SQLQuery[,varsList])
with a wrong rowDelim?

I make such mistakes all the time ...

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Bellballer1
Posts: 40
Joined: Sat Oct 24, 2015 5:42 pm

Re: Getting correct result from database using counter

Post by Bellballer1 » Wed Mar 23, 2016 2:38 am

Hi AxWald!

I do have the proper lines in tData. I continuously check that tData contains the proper lines.

I appreciate you taking a look!

Really, all I'm trying to do is get different numbers into the markers on my map. For example, I want the 1st marker to be labeled "6", the 2nd marker should have a label of "4" and so on. I just want the markers to have different labels.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”