this my main.lua
–local json = require (“json”)
–local myNewData
–local decodedData
–local SaveData = function ()–local function networkListener( event )
– if ( event.isError ) then
– print( “Network error!”)
– else
– print (“From server”)
– myNewData = event.response
– print ("From server: "…myNewData)
– decodedData = (json.decode( myNewData))
--SaveData()
– end
–end
–end
–network.request( “http://1dermindstudios.comyr.com/submitscore.php”, “GET”, networkListener )local SaveData = function()
local sqlite3 = require (“sqlite3”)
local myNewData
local json = require (“json”)
local decodedData–save new data to a sqlite file
– open SQLite database, if it doesn’t exist, create database
local path = system.pathForFile(“movies.sqlite”, system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
– setup the table if it doesn’t exist
local tablesetup = “CREATE TABLE IF NOT EXISTS mymovies (id INTEGER PRIMARY KEY, movie, year);”
db:exec( tablesetup )
print(tablesetup)
– save data to database
local counter = 1
local index = “movie”…counter
local movie = decodedData[index]
print(movie)
while (movie ~=nil) do
local tablefill =“INSERT INTO mymovies VALUES (NULL,’” … movie[2] … “’,’” … movie[3] …"’);"
print(tablefill)
db:exec( tablefill )
counter=counter+1
index = “movie”…counter
movie = decodedData[index]
end
– Everything is saved to SQLite database; close database
db:close()
–Load database contents to screen
– open database
local path = system.pathForFile(“movies.sqlite”, system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
--print all the table contents
local sql = “SELECT * FROM mymovies”
for row in db:nrows(sql) do
local text = row.movie…" "…row.year
local t = display.newText(text, 20, 30 * row.id, native.systemFont, 24)
t:setTextColor(255,255,255)
end
db:close()
end
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
myNewData = event.response
print ("From server: "…myNewData)
decodedData = (json.decode( myNewData))
SaveData()
end
end
network.request( “http://1dermindstudios.comyr.com/try.php”, “GET”, networkListener )
then this is my php
<?php
$host=“mysql6.000webhost.com”; //replace with your hostname
$username=“a9679956_caps2ne”; //replace with your username
$password=“blablabla”; //replace with your password
$db_name=“blablabla”; //replace with your database$con=mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name") or die (“cannot select DB”);mysql_select_db("$db_name") or die (“cannot select DB”);
$sql = “select * from mymovies”; //replace with your table name
$result = mysql_query($sql);
$json = array();
$count=0;
if(mysql_num_rows($result)){
while($row=mysql_fetch_row($result)) {
$count = $count+1;
$json[“movie”.$count]=$row;
}
}
mysql_close($db_name);
echo json_encode($json);
?>