PHP form - auto-calculate with database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
balmung17
Forum Newbie
Posts: 3
Joined: Thu Jun 04, 2009 2:58 am

PHP form - auto-calculate with database

Post 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. :-(
Last edited by balmung17 on Thu Jun 04, 2009 4:06 am, edited 1 time in total.
MeLight
Forum Commoner
Posts: 26
Joined: Sun Apr 19, 2009 12:39 pm
Location: Israel

Re: PHP auto-calculate with database

Post 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...
balmung17
Forum Newbie
Posts: 3
Joined: Thu Jun 04, 2009 2:58 am

Re: PHP auto-calculate with database

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHP auto-calculate with database

Post by onion2k »

balmung17 wrote:I really need this to be done urgently
Pay someone.
MeLight
Forum Commoner
Posts: 26
Joined: Sun Apr 19, 2009 12:39 pm
Location: Israel

Re: PHP form - auto-calculate with database

Post 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
balmung17
Forum Newbie
Posts: 3
Joined: Thu Jun 04, 2009 2:58 am

Re: PHP form - auto-calculate with database

Post 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?
Post Reply