Click here to Skip to main content
15,885,216 members
Articles / Web Development / HTML

A Simple AJAX Quiz Using Atlas

Rate me:
Please Sign up or sign in to vote.
4.08/5 (11 votes)
1 Aug 2006CPOL3 min read 80.7K   1.4K   33  
A simple way to create a quiz using Atlas controls and Web Services.
use [AjaxQuiz]
GO

CREATE TABLE [dbo].[t_Answers] (
	[AnswerID] [tinyint] IDENTITY (1, 1) NOT NULL ,
	[AnswerText] [nvarchar] (10) COLLATE French_CI_AS NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[t_Questions] (
	[QuestionID] [int] IDENTITY (1, 1) NOT NULL ,
	[QuestionText] [nvarchar] (500) COLLATE French_CI_AS NOT NULL ,
	[AnswerID] [tinyint] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[t_UserAnswers] (
	[UserAnswerID] [int] IDENTITY (1, 1) NOT NULL ,
	[UserID] [int] NOT NULL ,
	[AnswerID] [tinyint] NOT NULL ,
	[QuestionID] [int] NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[t_Answers] WITH NOCHECK ADD 
	CONSTRAINT [PK_t_Answers] PRIMARY KEY  CLUSTERED 
	(
		[AnswerID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[t_Questions] WITH NOCHECK ADD 
	CONSTRAINT [PK_t_Questions] PRIMARY KEY  CLUSTERED 
	(
		[QuestionID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[t_UserAnswers] WITH NOCHECK ADD 
	CONSTRAINT [PK_t_UserAnswers] PRIMARY KEY  CLUSTERED 
	(
		[UserAnswerID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[t_Questions] ADD 
	CONSTRAINT [FK_t_Questions_t_Answers] FOREIGN KEY 
	(
		[AnswerID]
	) REFERENCES [dbo].[t_Answers] (
		[AnswerID]
	)
GO

ALTER TABLE [dbo].[t_UserAnswers] ADD 
	CONSTRAINT [FK_t_UserAnswers_t_Questions] FOREIGN KEY 
	(
		[QuestionID]
	) REFERENCES [dbo].[t_Questions] (
		[QuestionID]
	),
	CONSTRAINT [FK_t_UserAnswers_t_UserAnswers] FOREIGN KEY 
	(
		[AnswerID]
	) REFERENCES [dbo].[t_Answers] (
		[AnswerID]
	)
GO

INSERT INTO [dbo].[t_Answers](AnswerText) VALUES('Yes')
INSERT INTO [dbo].[t_Answers](AnswerText) VALUES('No')
INSERT INTO [dbo].[t_Answers](AnswerText) VALUES('?')
GO

INSERT INTO [dbo].[t_Questions](QuestionText, AnswerID) VALUES('Do you usually have bread for breakfast?',1)
INSERT INTO [dbo].[t_Questions](QuestionText, AnswerID) VALUES('Have you ever been to Paris, France?',3)
INSERT INTO [dbo].[t_Questions](QuestionText, AnswerID) VALUES('Do you like what Microsoft created with Atlas?',1)
INSERT INTO [dbo].[t_Questions](QuestionText, AnswerID) VALUES('Do you program in VB.NET?',2)
INSERT INTO [dbo].[t_Questions](QuestionText, AnswerID) VALUES('Are you ready for the last question?',1)


/*
Name :  ProcessNextQuestion
Description :  SP used to process the quiz logic. If submitted data isn't null, it records user answer
				in t_UserAnswers table, then it sends data for next question.
Author :  Laurent Michaud
Changes :
	Description						Date			By
	Stored procedure created		2006/01/27		Laurent Michaud
*/
CREATE PROCEDURE dbo.ProcessNextQuestion 
	(
	@intQuestionID int = 0,
	@intAnswerID int = 0,
	@intUserID int = 0
	)
AS
	IF @intQuestionID > 0 AND @intAnswerID > 0 AND @intUserID > 0
	BEGIN
		INSERT INTO t_UserAnswers(UserID, AnswerID, QuestionID)
		VALUES(@intUserID, @intAnswerID, @intQuestionID)
	END
	
	SELECT TOP 1 QuestionID, QuestionText
	FROM t_Questions
	WHERE QuestionID > @intQuestionID

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
France France
I'm currently working for a transportation company in France and am responsible for software projects.

Comments and Discussions