Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 796 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Adding values in php?

Thread title: Adding values in php?
Closed Thread    
    Thread tools Search this thread Display Modes  
06-18-2007, 10:47 AM
#1
VividWire is offline VividWire
Status: Member
Join date: Apr 2006
Location:
Expertise:
Software:
 
Posts: 262
iTrader: 0 / 0%
 

VividWire is on a distinguished road

  Old  Adding values in php?

OK, i cant code php or any other useful language so I hope someone here can help me out.

I have a table, with lots of different rows, each row has a value in it. Can I total all the values and display it somewhere on the page?

Example:

0
1
1
0
1

total: 3
I may also need it to preform some kind of average, but lets not worry about that yet.

06-18-2007, 12:52 PM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

There are a number of approaches that you can take, I'll show you one initially. Since the values are being brought out of a database (assuming MySQL) then there are functions which you can use in the query to pull back the information you're looking for.

To total up a column of data, you can use:
Note: Replace mycolumn and mytable as appropriate
Code:
SELECT SUM(mycolumn) FROM mytable
Other similar functions like AVG (average), MAX (max value), MIN, COUNT (number of rows returned) can also be used.

06-18-2007, 01:28 PM
#3
DJAC is offline DJAC
DJAC's Avatar
Status: Member
Join date: Mar 2006
Location: Canada
Expertise:
Software:
 
Posts: 286
iTrader: 0 / 0%
 

DJAC is on a distinguished road

Send a message via MSN to DJAC

  Old

Assuming you are reading your values "0 1 1 0 1" from a database, you can create a new variable, let's say mySum. Every time you read a value from your database, output it to your table AND add it to mySum.

After reading all your values, you can simply output mySum.

06-20-2007, 09:43 AM
#4
VividWire is offline VividWire
Status: Member
Join date: Apr 2006
Location:
Expertise:
Software:
 
Posts: 262
iTrader: 0 / 0%
 

VividWire is on a distinguished road

  Old

I am affraid there is no database, the information doesnt need to be stored just output to the screen.

I also discovered that it will actually be adding up values from a layer rather than rows in table.


here is a bigger outline:

Page 1
The user answers yes or no questions, if they choose 'YES' the text in layer 1 changes to '1', they answer the next question if they choose 'NO' the text in layer 2 is set to '0', or left blank.

After all of the questions are filled in the user presses a 'reveal' button, which shows page 2.


Page 2 (initialy hidden)
contains layer 1, layer 2 etc.

Needs the ability to add together the '1's on the page to come up with a total. I then need to be able to use this total to come up with a average.


Make sense?

I hope this is possible... it is really important.

Thanks for you help!

06-20-2007, 10:24 AM
#5
TheCodeNinja is offline TheCodeNinja
Status: Junior Member
Join date: Apr 2007
Location:
Expertise:
Software:
 
Posts: 95
iTrader: 1 / 100%
 

TheCodeNinja is on a distinguished road

  Old

Hmmm...if you want to do this with PHP, you'll either have to put the values from the layers in hidden form controls, or put them together in a query string...both of those options are a bit of a pain.

Either of those options would require JavaScript though, since you're wanting the values from layers instead of the radio buttons themselves. And if you're using JavaScript, there are better solutions.

Seems like this is a case of "not enough info." Can you upload it somewhere so we can help you? Even for a Code Ninja, this is a rather vague problem

06-22-2007, 12:08 AM
#6
bluesaga is offline bluesaga
Status: Member
Join date: Feb 2007
Location:
Expertise:
Software:
 
Posts: 137
iTrader: 1 / 100%
 

bluesaga is on a distinguished road

  Old

From the sounds of things your needing a javascript thing to add it all together and display the result. Using php, you could add the results from the form together and simply output the results to the browser, might be your better choice?

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed