Forum Moderators: open

Message Too Old, No Replies

manipulating data

working with phpmyadmin

         

Light_Gear

3:22 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



What I want to do is this.

Take form questions and insert them into a database which is easy. Then take the data from the database and combine certain questions to get a average in a different column.

i.e. question --> do you agree with this person?
strongly disagree, disagree, mildly disagree, mildly agree, agree, strongly agree

They would pick one and it would be inserted.

Now I would take question 1-5 and average them out and display the results.

I have worked with phpmyadmin some but am not sure how to go about combining data and would like the helpful adivice of this board since their are alot more people with more.

Also is there any good tutorials on the subject anyone can recommend.

Demaestro

4:21 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is an SQL function call AVG. It is used to get the average value from a field.

In your example you said the chioces to a questions was something like:

strongly disagree, disagree, mildly disagree, mildly agree, agree, strongly agree

What you want to do is aassign each one of these a numeric value and store that in a lookup table. So rather then storing "strongly disagree" you store a 1 and instead of "strongly agree" you store a 7. Then what you do is run a query like this:

Select
AVG(agree_level)
from
table
where
this = that

So if this above query returns a 3 then you know the average is "mildly disagree".

Hope this helps

Light_Gear

4:49 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Yes it does it gives me a direction to work in.

Thanks

Light_Gear

9:24 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Ok one more thing

Can the avg( ) be done from with in phpmyadmin or does it have to be done on the web page before it get to the database

Demaestro

10:00 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can the avg( ) be done from with in phpmyadmin or does it have to be done on the web page before it get to the database

When you set up the SQL query it should be part of that statement, it is an SQL function. Not sure how this looks in php but it is something like.

sql.execute(select avg(agree_level) from table)

Sorry I don't know PHP but if you ask someone in the PHP section to give you the syntax for this sql then you will have what you need. but if you were to execute this statement directly it will gve you want you want.

Select
AVG(agree_level)
from
table
where
this = that