Row calculation problem

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
jc_ply
Forum Newbie
Posts: 5
Joined: Wed Mar 19, 2008 11:38 pm

Row calculation problem

Post by jc_ply »

Hey guys, you were so helpful with my last issue (which I'm very greatful for) I'm back to share another growing pain, and the last for now at least.

my row is looking like this:

network | user_amt | war_one | war_two | war_three | war_four | war_five
sample ----- 50 ------- 70 -------- 5 --------- 8 -------- 3 -------- 9

the war_one - five fields are just counters for the users selections but I need to calculate the highest value from the last five war fields (e.g 70) and divide it by the total value of the war fields (e.g 95) then times by 100 to return a percentage along with the highest fields name.

I have similar set ups in the database where the same returns are needed but their universal and can be column calculated where as this table is network specific so proving to be a bit difficult (for my learner level php)

Any help would be as always greatly appreciated ,

Jason
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Row calculation problem

Post by onion2k »

Your database structure will make this a total nightmare to do in SQL. Fetch the data from the database and do the calculation in PHP. Better yet, redesign the database to hold the score values in a better way (eg 1 per row).
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Row calculation problem

Post by pickle »

~onion2k is right - you should redesign your database. Give each row 3 columns - `network`, `user`, and `war`. It'll then be much easier to do complex queries.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply