Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Updating Table Using an Event Listener and SQ LITE
Started by binky Aug 15 2018 07:00 PM

- - - - -
No replies to this topic
help coding database tables listener
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

binky

[GLOBAL: userInfoPane.html]
binky
  • Observer

  • 9 posts
  • Corona SDK

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



[topic_controls]
[/topic_controls]