Discussion Forums  >  Uncategorized

Replies: 17    Views: 358

GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
11/07/11 01:55 PM (14 years ago)

Locations File : DataURL PHP (Doesn't Work) vs TXT (Does Work!)

Hi, I have a database of latitude and longitude points, along with some comments. I want to create a location screen that is populated with the points from that database. I wrote a PHP script that queries the database, pulls out the information, and formats it in correct JSON format. I validated the output online. The problem I'm having is that if I set the DataURL in my control panel to the .php file, I get an error saying invalid format. However, if I run the script, dump the data to a text file, and then point the DataURL to the file (which has the EXACT same output as the PHP script), everything works! Is it possible that my app is having problems processing the output from the PHP file on the fly? Should it work having the DataURL call a PHP file, or does it only work with a text file of points (in correct JSON format)? Thanks! Mark
 
Parker @ buzztouch
buzztouch Evangelist
Profile
Posts: 1395
Reg: May 09, 2011
Pacific Grove, ...
24,500
like
11/07/11 09:17 PM (14 years ago)
Hi Mark, How are you using the .php file to return the JSON?
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
11/07/11 09:52 PM (14 years ago)
Hi Parker, Here is the PHP that I call from the DataURL. Minus all the necessary quotes that get stripped from the forum, of course : <?php $db = mysql_connect(localhost, user, password); mysql_select_db(dbname,$db); $result = mysql_query(SELECT ID, Latitude, Longitude, Description from tablename,$db); $num = mysql_num_rows($result); $i = 1; print {\childItems\:[<br>; if ($myrow = mysql_fetch_array($result)) do { printf(  {\itemId\:\%s\,<br>, $myrow[ID]); print   \itemType\:\BT_MapLocation\,<br>; printf(  \latitude\:\%s\,<br>, $myrow[Latitude]); printf(  \longitude\:\%s\,<br>, $myrow[Longitude]); printf(  \title\:\%s\}, $myrow[Description]); if ($num > $i) printf(,); printf(<br><br>); $i++; } while ($myrow = mysql_fetch_array($result)); else { echo Sorry, nothing there to see!; } print <br>]}; ?> You can see the output from that here --> http://www.cityshotspots.com/location-list.php If you run the output through the JSON validator, it comes up clean, and it's formatted in the exact format you guys specify in your example. If I take that output, create a txt file with it, and send the DataURL to that txt file...it all works! Thanks, Mark
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
11/08/11 11:33 PM (14 years ago)
easy fix. a) Load the URL you posted in your browser. Looks good right.... b) View Source in browser to see actual data (not HTML!). Looks good right...wrong! The clue that led me to find this was the carriage returns, br tags in this case. THe text data the app is getting is NOT valid json, it's html with markup, spacing, etc. If you copy-paste form your browser to a text file you're not getting the HTML so it makes sense that this would work. Lose the HTML in the php output and all will be find. If you really want it to be pretty when loaded in a browser, use /n instead of br to force a line break that is hidden, not visible. My preference is to just remove all the line breaks altogether - no need for them in JSON. Back to BT-server...2.0.7 out tomorrow night.
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
11/08/11 11:40 PM (14 years ago)
Dang, @David...you rock! Thank you very much for taking a look at that...makes perfect sense! I'll make the fix and report hopefully report back success! Appreciate you taking a break from your BT-server 2.0.7 work to help me out!
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
11/18/11 04:06 PM (14 years ago)
Stripped out all the HTML stuff and got it working...awesome stuff!
 
Parker @ buzztouch
buzztouch Evangelist
Profile
Posts: 1395
Reg: May 09, 2011
Pacific Grove, ...
24,500
like
11/20/11 05:44 PM (14 years ago)
Excellent! Glad you got it working!
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/03/12 03:37 PM (14 years ago)
I am having the same problem with my quiz app. I went through and stripped out all of the html tags and JSON validated it too, but the app still won't pick it up. The .txt file does work though, but I would like to use the .php if possible any thoughts?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/04/12 02:56 PM (14 years ago)
'the app wont' pick it up' - not sure what this means. Paste the URL in the Data URL box for the quiz. As long as the URL loads a list of childItems (questions) it'll be fine. What happens when you load the questions in your browser (using the URL), do they look right? Maybe post the URL here so we can see your quiz questions.
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/04/12 10:32 PM (14 years ago)
Thanks David. What I meant with the comment was that there is a parsing error when I try to direct the app to the php url. When I load the URL into my browser it looks right, but there is no hard returns between the individual questions. That is not needed right? Here it is: http://www.myquizcoach.com/extras/quiz_JSON_template.php Let me know what you think. Thanks in advance.
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
01/04/12 11:26 PM (14 years ago)
Hi @Maune12, Try this : * Go to the URL you pasted above * Copy all the output (Ctrl-C) * Go to jsonlint.org, and paste the data into the box * Notice the error on line 152 * Fix error ;-) You might have a hard return in that entry or something. I bet when you fix that particular piece of data, it'll all work. Mark
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/05/12 02:56 AM (14 years ago)
For sure you'll want to validate it. FYI. Carriage returns are OK in the data so long as they are between items. In fact, JSON becomes much easier to read when it's properly tabbed and spaced. The trick is to no introduce any of the special characters in the data itself. Example, validate something at the validator @GoNorthwest mentions, you'll see how it formats. This URL to this data loads a very large dataset. Because of this it's likely that the items come from a database or spreadsheet. I would being debuggin the JSON by limiting the output. Say like 20 questions at a time until you find the bogus ones ;-)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/05/12 02:57 AM (14 years ago)
Oh lastly, because you say the .txt version works but the .php version does not, it's very very likely that your .PHP script has slipped in a carriage return (in the data) or an apostrophe or something where it should not. Again, debug in sections until you find it.
 
Annonymous
Profile
01/05/12 09:14 AM (14 years ago)
Thanks David. What I meant with the comment was that there is a parsing error when I try to direct the app to the php url. When I load the URL into my browser it looks right, but there is no hard returns between the individual questions. That is not needed right? Here it is: http://www.myquizcoach.com/extras/quiz_JSON_template.php Let me know what you think. Thanks in advance.
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/05/12 02:37 PM (14 years ago)
Thanks for the replies. I did check out the validator that @GoNorthWest discussed above (before I posted the original post). After the replies I checked the line he described, but I didn't get an error nor did it look strange in the validator when I copied and pasted the output from the URL into the validator. However, when I went through the option to enter in the URL into the validator and placed ?reformat=compress after the URL I did see the carriage return :) It was an extra return that I had in the database and not a problem with the script. Thanks again. I don't know why it took placing the URL into the validator to see it, but maybe this will help others. FINALLY!!!!!
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/14/12 11:22 AM (14 years ago)
Now that the script is working for me, I was wondering if someone could give me some advice on how to randomize the answers for the questions on the v1.5 quiz with php. I pastes my code on this thread: http://www.buzztouch.com/forum/thread.php?tid=CEE507C4B8B22BF950242B1&status=&searchInput=Randomize&sortColumn=FT.dateStampUTC&sortUpDown=DESC¤tPage=1&doViews=1 I know it might be a messy script (I'm welcome to any suggestions to clean it up) but it works. Thank you in advance.
 
muhromatic
buzztouch Evangelist
Profile
Posts: 24
Reg: Dec 19, 2011
NYC
240
like
01/14/12 08:41 PM (14 years ago)
Good Stuff... Would it be possible to include a URL field in the sql database and have each map point open up a custom URL screen displaying the associated URL?
 
themc
Code is Art
Profile
Posts: 75
Reg: Nov 11, 2011
Tilburg
7,050
like
09/04/12 02:53 AM (13 years ago)
hello i used Gonorthwest document for the maps. i got it working. it failed in the first place because i used * in the desription part of the text. thnx north for your turorial. i have a question do wich might be a bit technical. is it possible to popup a image + a website link to an article in this script? so when it shows a result (red pin) it displays an image and weblink to an article.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.