views:

162

answers:

6

I do a bit of HTML/CSS for fun but I am looking at picking up some programming skills.

I have been reading up on PHP and MySQL. So far I have not found it too hard understanding the concepts such as loops, condition statements etc but I want to get stuck in and start developing an app before I get too bored reading and giving up completely.

My idea...

I happen to be studying for an exam at the moment and have these practice exams on paper. I thought why not put this into an app so I can take the exam on the computer.

Features:

  • The app can hold multiple exams
  • It can randomise questions or display them in order
  • Have the option to display answer for each question
  • Time the duration to complete the exam
  • Admin page to add new exams and questions/answers

Ok, you guys can stop laughing now, I know this is one step above Hello World but thought I'd make a start somewhere!

I will develop this in PHP/MYSQL or maybe RoR if you guys think its better for a beginner. I think I will be ok reading/writing to the DB but I'm not so sure on site structure, DB design and generally best to way to do it.

If I have an exam made up of 50 questions, each given an ID. If I delete one question how do I update the rest with new IDs? I.e. if I delete question 3, all following questions need to shift their ID back by 1.

EDIT:

How would I represent an instance of one exam in my database schema? The exam and question relationship will be one to many, since questions will be unique to a single exam. But since I am aiming to have multiple exams, how do I represent that?

+2  A: 

Your biggest thing here, in my opinion, will be the structure of your database. You're going to want to read up a bit about db-design, and normalisation. Basically you'll want to logically plan out the different entities that exist in your application:

  1. Exams
  2. Exam Takers
  3. Questions
  4. Answers

And some of these will be tied to eachother:

  1. Questions -> Exams
  2. Takers -> Exams
  3. Answers -> Questions

Whenever you have situations like this, you need to determine whether the relationship is one-to-one, one-to-many, or many-to-many. Questions could belong to one exam, or many. That's up for you to decide. If a Question belongs to only a single Exam, you can create a field in your Question table to hold an ExamID. If a Question can belong to many exams, you'll create a new table with two fields: QuestionID, ExamID. This builds your many-to-many relationship.

In all honesty, this could be a very large and difficult undertaking for somebody who has very little programming experience. In my opinion, you should start with something much simpler, like a guestbook or a mini-blog.

Regardless what application you decide to build, SO is here for you all along the way.

Jonathan Sampson
+7  A: 

OK, first of all, welcome :) Second of all: yours is not a stupid idea at all, in fact, you have chosen the best way to learn how to program: do something useful and fun.

To get to your question: why do you need consecutive IDs for the questions? Database-wise, you just need to have different IDs per row.

If it is a display requirement, why don't you assign a number over a loop during display? So, for example when you do a foreach to display the questions you can keep an index variable which you increment at each loop, and use that to display the ordinal.

Hope this is what you are looking for, good luck!

Sklivvz
Oh yes! that makes sense. I'll just generate the IDs as I loop through them. I think I need to get a brain before I can program :p I guess this relates to what Rich says below about never deleting Primary IDs.
Jon
@Jon, not *exactly*, you should generate the question numbers as you loop through them, but the IDs should be left alone once they're assinged in the Db, as Rich Apodaca points out in his answer.
David Thomas
I think part of the confusion may be what "ID" means: (i) in the database, the primary key for each question should _never_ change; (ii) in the user interface, the question number displayed to the user should be dynamically-generated, as I suggested in my answer.
Argalatyr
@Argalatyr: +1, exactly =)
David Thomas
+1  A: 

A specific application is an excellent way to learn programming, even if such applications already exist (and they do - but I would avoid looking at those, just create and learn!).

One of your specifications is that the questions can be displayed in any order. Another is that they can be removed. So, it's clear that the numbering is not directly related to the question - it should be generated dynamically once the set of questions, and their order in the test, has been established. You need to think through these requirements, which provide the basis for design of the components. The user interface should be insulated from the program logic, which should be insulated from the database of questions. Try to pass information between these parts in the most primitive form possible. That way, when you want to redesign one of the layers, you won't have to change the whole thing.

Argalatyr
BTW, you may want to permit storage and display of a markup language like HTML in your questions and answers, and use CSS or similar, so that you can format the text!
Argalatyr
+2  A: 

If I have an exam made up of 50 questions, each given an ID. If I delete one question how do I update the rest with new IDs? I.e. if I delete question 3, all following questions need to shift their ID back by 1.

Primary IDs shouldn't ever change. When you delete one row in your table, the corresponding primary ID just disappears, but there should be no renumbering of the other row primary keys.

If you decide to go with Rails, check out Ryan Bates' excellent screencast site Railscasts.

Rich Apodaca
+1  A: 

I agree with all the other answers, implementing an useful application is a great way to learn web development. But, as Jonathan said, it's not a very simple application that you are planning to build. That said, here are my thoughts:

Ruby on Rails is a framework for Ruby. It can also utilize MySQL. PHP is a programming language (as ruby is for RoR), and provides no framework. There are quite a few for PHP though, CodeIgniter, Zend Framework, Symfony or CakePHP to name a few. Frameworks implement often-used aspects of an application in a flexible way, so they can be used for various applications. Some of these aspects may be authentication, database access, caching, template rendering and a lot more.

Frameworks are usually written to speed up application development, if you choose php, you might want to try to write your own framework, if your primary goal is learning. You should still take a look at the other frameworks and try them out to see what they are and how they work.

I would recommend to follow through a few tutorials for one or two frameworks, and to research everything you don't already know (MVC, Coding patterns, etc.). I find the english wikipedia very helpful.

The other part of your application will be the database. Some frameworks offer some kind of ORM, which will "shield" the database access from you, once you have set up your schema. I would still recommend to take a look at how to query a database, because you then know what the framework does when it retrieves data from the database.

This seems to be a good resource for an intro to the mysql-server, and contains some links to sql-tutorials (for querying the db-server). And I would recommend this tutorial on how to create your database schema.

I hope some of these resources are useful to you and wish you good luck.

Thomas
Thanks for the info. I think I am going to stick with this project and make a start with the DB Schema. That tutorial you linked on normalization looks very useful.
Jon
A: 

How would I represent an instance of one exam in my database schema? The exam and question relationship will be one to many, since questions will be unique to a single exam. But since I am aiming to have multiple exams, how do I represent that?

Jon