livecode server return json

Are you using LiveCode to create server scripts or CGIs?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
klamp
Posts: 12
Joined: Sun Sep 20, 2020 10:36 am

livecode server return json

Post by klamp » Sun Sep 20, 2020 10:48 am

Hai,

i am learning livecode mysql queries return json.
how do i do it?

Code: Select all

<?lc
	put "livecodecom" into tDatabaseAddress
	put "runrev_test" into tDatabaseName
	put "runrev_example" into tDatabaseUser
	put "example" into tDatabasePassword

	put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
	if tResult is a number then
	put tResult into gConnectionID
	
	put "Table1" into tTableName	-- set this to the name of a table in your database
	put "SELECT * FROM " & tTableName into tSQL
	
	-- query the database
	put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
	
	put tData
?>
how do i get tData to return json?

Thanks
Last edited by klamp on Sun Sep 20, 2020 11:34 am, edited 1 time in total.

Klaus
Posts: 12132
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: livecode server return json

Post by Klaus » Sun Sep 20, 2020 11:04 am

Hi klamp,

welcome to the forum!

Hm, you will need to:
1. Create an array from tData
2. Then turn this array to a JSON with -> ArrayToJson(the_array_from_tData) and "put" this.
But on the client or server side, you have to do it this way.


Best

Klaus

klamp
Posts: 12
Joined: Sun Sep 20, 2020 10:36 am

Re: livecode server return json

Post by klamp » Sun Sep 20, 2020 11:17 am

thank you for answering Klaus

is there any tutorial to convert tDaya to array?
I am still confused.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 927
Joined: Fri Aug 15, 2008 7:15 am

Re: livecode server return json

Post by bangkok » Sun Sep 20, 2020 4:07 pm

klamp wrote:
Sun Sep 20, 2020 11:17 am
is there any tutorial to convert tDaya to array?
Before to try to convert things, you need first to really understand what are arrays...

Here is a good intro :

http://livecode.byu.edu/arrays/introToArrays.php

klamp
Posts: 12
Joined: Sun Sep 20, 2020 10:36 am

Re: livecode server return json

Post by klamp » Mon Sep 21, 2020 11:10 am

thanks Bangkok.

Post Reply

Return to “CGIs and the Server”