0
votes

I am new to Corona and I have a set of 10 question and the input is in the range from 0-8. I have code it such that my numeric textbox will loop for i times (i = number of question in array).
My question is how do I insert these value that is being keyed in into the database that i have created? Do i need to assign these individual question with a variable?

local madrs = display.newGroup()
local function textListener( event )
if ( event.phase == "began" ) then

elseif ( event.phase == "ended" or event.phase == "submitted" ) then
    -- Output resulting text from "defaultField"

print( event.target.text )

elseif ( event.phase == "editing" ) then
    print( event.newCharacters )
    print( event.oldText )
    print( event.startPosition )
    print( event.text )
    end
end
-- Create text field
madrs = native.newTextField( 640, 150 + (i * 450), 100, 100 )
madrs.inputType = "number"
madrs:addEventListener( "userInput", textListener )
madrs.font = native.newFont( native.systemFontBold, 50 )
scrollView:insert( madrs )

If you are unsure of what i am asking, feel free to comment down below i will clarify the question with you.

1
Please add what database you are using. I don't think you need to assign each question with a separate variable. You can use a table or even a string just with the values added together. - creyD
i am using SQLite DB. i have updated my code above for the textbox loop please look again. Originally all the textbox is radio button, i am able to update it into the DB. Right now i need the radio button change to textbox but the value entered in the textbox is not loaded into the DB. if you want to see my previous radio button code, it is in stackoverflow.com/questions/48184075/… Thankss - NoobProgrammer
@creyD i also realise that id = tostring(i) is the line of code that push all radio value into the table. you can see in here stackoverflow.com/questions/48184075/… So am i right to say that if i am able to infuse this line of code properly in the textbox loop and my function work? - NoobProgrammer
I am fairly sorry, but I can't answer your question as I never worked with corona... - creyD
@creyD it okay! :) really appreciate you for your help - NoobProgrammer

1 Answers

-1
votes

You first need to ask yourself if you really need a SQL/SQLite database to store your data. I would say that 99% of the Corona apps would run as fine if you just store the data as a txt file (usually using JSON format).

If you still want to use SQLite, just take a look at the documentation for you. It provides example on how to execute queries (in your case, INSERT)

Link for Corona/Lua SQLite : https://docs.coronalabs.com/api/library/sqlite3/index.html