So I am trying to make a timetable app that changes the periods your have on that day determined on that day… The user is able to switch between the days using buttons and tables… Regardless I am just starting to use SQ LITE and am trying to create a function that allows the user to update certain periods after they have touched the text. It works however if I update the text at the end of the week (Friday) all the text prior to that day gets updated also. Thanks for anyone who can help!
function scene:create( event ) local sceneGroup = self.view -- creating blank table to store stuff local periods = {} -- /\* Function(s) /\* -- local function period\_display( day ) local counter = 1 for row in db:nrows("SELECT \* FROM" .. " " .. day) do local text = row.period --print(periods[counter]) local function period\_touch\_event( event ) if event.phase == "ended" then local tableedit = [[UPDATE]] .. " " .. day .. " " .. [[SET period = "mk" WHERE id=]] .. row.id ..[[;]] db:exec (tableedit) end end if periods[counter] and periods[counter].removeSelf then periods[counter].text = text else periods[counter] = display.newText( text, cW + 50 , 130 + (55 \* row.id), nil, 16 ) periods[counter]:setFillColor( 1, 0, 0, 1 ) sceneGroup:insert( periods[counter] ) end print (periods[counter]) periods[counter]:addEventListener("touch", period\_touch\_event) counter = counter + 1 end end -- Function to change the periods shown local function day\_touch\_event( event ) local id = event.target.id if event.phase == "ended" then if id == "+" then if selected\_day \< 5 then selected\_day = selected\_day + 1 end end if id == "-" then if selected\_day \> 1 then selected\_day = selected\_day - 1 end end display\_stuff.text = ( current\_day[selected\_day] ) -- /\* insert sqlite stuff here to present the data depending on the day /\* -- if selected\_day == 1 then period\_display("day\_1") end if selected\_day == 2 then period\_display("day\_2") end if selected\_day == 3 then period\_display("day\_3") end if selected\_day == 4 then period\_display("day\_4") end if selected\_day == 5 then period\_display("day\_5") end -- \*/ insert sqlite stuff here to present the data depending on the day \*/ -- end end -- \*/ Function(s) \*/ -- if m\_opened == 0 then -- insert data base shiet timer.performWithDelay( 0, delay\_event ) m\_opened = 1 end if m\_opened == 1 then -- Drawing the 'stuff' onto the screen back\_button = display.newText( "home", cW, cH \* 2 - 50, native.systemFont, 16 ) period\_rec = display.newLine( 50, 65, 50, cH \* 2 - 65 ) -- Using the append function to draw a rec period\_rec:append( cW \* 2 - 50, cH \* 2 - 65, cW \* 2 - 50, 65 , 50, 65 ) -- b1g m4th -- Apply stroke width and color and stuff period\_rec:setStrokeColor( 0, 0, 0, 1 ) period\_rec.strokeWidth = 1 -- Setting the color to the object back\_button:setTextColor( 0, 0, 0, 1 ) -- Adding all of the object listeners back\_button:addEventListener( "touch", home\_button ) -- Adding all of the buttons to the scene group so they are removed when the scene isnt shown sceneGroup:insert( back\_button ) sceneGroup:insert( period\_rec ) sceneGroup:insert( display\_stuff ) -- sceneGroup:insert( drawButton()) -- Function to draw the buttons 'dryly' local function draw\_button( button\_id, x\_value, y\_value ) local button = display.newText( button\_id, x\_value, y\_value, native.systemFont, 16 ) button:setTextColor( 0, 0, 0, 1 ) button.id = button\_id button:addEventListener( "touch", day\_touch\_event ) return button end -- For loops using tables for i = 1, #button\_name do local button = draw\_button( button\_name[i][1], button\_name[i][2], button\_name[i][3]) sceneGroup:insert(button) end for i = 1, #periods\_1 do --60 and cH \* 2 - 60 local ok = display.newText( periods\_1[i], cW - 50, 75 + (i \* 55), native.systemFont, 16 ) ok:setTextColor( 0, 0, 0, 1 ) --ok:addEventListener("touch", period\_touch\_event) sceneGroup:insert( ok ) end end end