Reading data from MySQL database, using PHP, I get the following (using the http request in Corona) data from the table: [[“Alex”,35],[“John”,28]]. Unfortunately it comes as string (so I have to read myTable[1]), and I cannot get the reality (in this example, 2 records, with 2 fields each).
I tried the JSON.lua but the only thing it is doing is something like [""["…
What is the best way to get the results from my PHP script as a Lua array/table, instead the simple text? If someone is kind enough to check the returning from my php script, just try it at http://www.ppgplaces.com/getPilots.php
thanks a lot, Alex [import]uid: 4883 topic_id: 2584 reply_id: 302584[/import]
http = require("socket.http")
crypto = require("crypto")
ltn12 = require("ltn12")
url = require("socket.url")
require("Json")
local json = {}
local response = {}
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
local r, c, h = http.request {
url = "http://www.ppgplaces.com/getPilots.php",
sink = ltn12.sink.table(response)
}
json = Json.Decode(table.concat(response,''))
local path = system.pathForFile("r.txt", system.DocumentsDirectory)
local file = io.open (path, "w")
print(dump(response))
Tim [import]uid: 8196 topic_id: 2584 reply_id: 7480[/import]