Page 1 of 1

PHP form - auto-calculate with database

Posted: Thu Jun 04, 2009 3:03 am
by balmung17
Hi I'm a newbie.
I hope someone can help me on this....

I'm trying to build an PHP evaluation form which rates answers from 1-5. When user inputs an answer it will store up on a database. And if another user inputs a value, it will add the data and compute for it's average.

Here's a computation sample:
3 user rated their answers from 1 to 5. Let's say they all rate it at 5, so it will give me 3 points to rate5. Then it will multiply the no. of users who rate 5 by the rate. So 3*5 = 15, then It'll divide it by the no. of users who voted 5, so 15/3 = 5.
Another sample is like this:
total 5 users
3 rated it 5
2 rated it 4

so 3*5/5 = 3.0 - where 3 is the no. of votes * 5(rate) divided by 5 (no. of voters)
and 2*4/5 = 1.6

I know this one is tough but i'll appreciate it very much if someone can give me a script for this. Thanks in advanced.

*note:
I also don't know how to make table.sql for this. :-(

Re: PHP auto-calculate with database

Posted: Thu Jun 04, 2009 3:16 am
by MeLight
That's how create a table.

Code: Select all

 
$sql = "CREATE TABLE Ratings
(
    Rating int,
    NumOfRaters int
)";
 
// Execute query
mysql_query($sql,$con);
 
You havn't supplied much info about how you actually want the user to input the data etc. And you havn't showed any attempted code, so there's not much to fix...

Re: PHP auto-calculate with database

Posted: Thu Jun 04, 2009 4:01 am
by balmung17
Thanks for quick reply.
Actually, that's exactly the problem. I don't know where to start, and I don't know how to code :-( but that's what I want to happen.
The output will be like this

Course Evaluation

Date: (auto-date)
What course did you just complete? (radiobutton1)Course1 (radiobutton2)Course2

1. The course met its objective (rb)1 (rb)2 (rb)3 (rb)4 (rb)5
2. The course was presented clearly. (rb)1 (rb)2 (rb)3 (rb)4 (rb)5
3 blah blah blah (rb)1 (rb)2 (rb)3 (rb)4 (rb)5

Then after they hit submit, the result will be forwarded to mysql database.
Then if another user take the evaluation agaiin the results will be added to the database, overwriting the previous and compute for the grade. And then, there will be an admin page where only I can access and see the report/result.

I know it's troublesome, but I really need this to be done urgently :-(
Thank you.

Re: PHP auto-calculate with database

Posted: Thu Jun 04, 2009 4:44 am
by onion2k
balmung17 wrote:I really need this to be done urgently
Pay someone.

Re: PHP form - auto-calculate with database

Posted: Thu Jun 04, 2009 5:02 am
by MeLight
This is probably one of the best tuts for PHP MySQL thingies, really short and probably has everything you need. If you go through all of it (about an hour or so) you should be able to write that thing you need.

w3schools PHP MySQL
w3schools PHP Forms

Re: PHP form - auto-calculate with database

Posted: Mon Jul 06, 2009 8:31 pm
by balmung17
Actually I found a component for joomla called bf survey, it got resolved my issue for having a survey questions. Then it computes and reports it on my email and on a database. The results are also graphed. But the problem is its not the computation I want. Is it possible to be modified for my need?