[PHP-DB] calculations using variables in html table cell
I am generating html tables dynamically. Each table has multiple columns and various calculations need to be done on each column and displayed at the bottom of the column. I am including the code from one table below. The $tablerow generates the table data and the $tablefooter generates the rows at the bottom that will include the calculated values. Preceding the $tablerow declaration, I have declared some variables and done calculations. I then included these in the $tablefooter to display the calculated values. This works fine. However, I have many other calculations on other columns in other tables. Using this method, I would have to declare many new variables just for calculations. I am wondering if there is a way to do these calculations directly in the table cells. I am pretty new to PHP and have not used calculations much. $sumpop += $POP; $sumadultcirc += $ADULTCIRC; $sumjuvcirc += $JUVCIRC; $tablerow[1] = trtd . $row[name] . /td . td$POPtd$ADULTCIRC/td td$JUVCIRC/tdtd$TOTCIRC/tdtd$CIRCPERCAP/tdtd$TOTREF/tdtd$R EFPERCAP/td/tr; $tablefooter[1] = trtdbTable total/b/tdtdb$sumpop/b/td tdb$sumadultcirc/b/tdtdb$sumjuvcirc/b/tdtdb$TOTCIRC/b /td tdb$CIRCPERCAP/b/tdtdb$TOTREF/b/tdtdb$refpercap/b/td /tr trtdbTable average or per capita/b/tdtdb$POPAV/b/td tdb$ADCIRCAV/b/tdtdb$JUDCIRCAV/b/tdtdb$TOTCIRCAV/b/td tdb$CIRCPERAV/btdb$TOTREFAV/btdb$REPERAV/b/td/tr; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] calculations using variables in html table cell
If you have to build complex, dynamic tables, do yourself a favour and use a class that will allow you to feed directly arrays of numbers. I use PEAR HTML_Table, which is great and easy to use. You will have recouped the investment of learning the class after about one hour. HTH Ignatius _ - Original Message - From: Christopher Adams [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, December 03, 2003 21:07 Subject: [PHP-DB] calculations using variables in html table cell I am generating html tables dynamically. Each table has multiple columns and various calculations need to be done on each column and displayed at the bottom of the column. I am including the code from one table below. The $tablerow generates the table data and the $tablefooter generates the rows at the bottom that will include the calculated values. Preceding the $tablerow declaration, I have declared some variables and done calculations. I then included these in the $tablefooter to display the calculated values. This works fine. However, I have many other calculations on other columns in other tables. Using this method, I would have to declare many new variables just for calculations. I am wondering if there is a way to do these calculations directly in the table cells. I am pretty new to PHP and have not used calculations much. $sumpop += $POP; $sumadultcirc += $ADULTCIRC; $sumjuvcirc += $JUVCIRC; $tablerow[1] = trtd . $row[name] . /td . td$POPtd$ADULTCIRC/td td$JUVCIRC/tdtd$TOTCIRC/tdtd$CIRCPERCAP/tdtd$TOTREF/tdtd$R EFPERCAP/td/tr; $tablefooter[1] = trtdbTable total/b/tdtdb$sumpop/b/td tdb$sumadultcirc/b/tdtdb$sumjuvcirc/b/tdtdb$TOTCIRC/b /td tdb$CIRCPERCAP/b/tdtdb$TOTREF/b/tdtdb$refpercap/b/td /tr trtdbTable average or per capita/b/tdtdb$POPAV/b/td tdb$ADCIRCAV/b/tdtdb$JUDCIRCAV/b/tdtdb$TOTCIRCAV/b/td tdb$CIRCPERAV/btdb$TOTREFAV/btdb$REPERAV/b/td/tr; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Calculations
Hi, I am not sure if this is possible or not or in what format etc. Maybe it's a PHP, mysql or even a JavaScript thing. But thought I'd post here and see if people are aware if it is possible for what I want to do. I have searched alot on the net and yet have not come accross what I am looking for, so posting here may get me pointed in the right direction. Okay here is what I wanna do. :) I have a list of users in multiple tables in the one database. Each user has a field named 'score'. As the table numbers go higher generally the score goes higher but never lower than the previous table. There are 22 tables named 1 to 22. So an example is below: table 1: User: bob Score: 7 table 2: User: bob Score: 10 table 3: User: bob Score: 16 So the scores go up and never down from the previous table value. Now what I want to output on a page is not 7, 10, 16 but output the difference from the current table and the table before it. So obviously table 1 would not be changed from 7 but table 2 would need to output 3 and table 3 would output 6. So I need to output not the value but the difference between the current table and the table before it and if there is no table before it the value would be the same or in other words the value minus 0. Is there either a mysql query I can use for this or would I use a JavaScript bit of code to work out the difference and output it? The code will need to connect to the database and retrieve values and users from all 22 tables and cores and somehow output the difference, is this possible? Table 22 has the total amount after all tables, So I don't need a total figure worked out. (E.G. Aadding all the scores together) Is it possible, or a bit complicated? I know this is a bit of a pain but already the scores have been worked out, I should of created another field to get the table score for that round from the start and keep it but I did not think of that earlier in the year. If it's tto much work I wont bother about it, but thought I'd ask and see if anyone can help. Thanks! Jerry http://search.yahoo.com.au - Yahoo! Search - Looking for more? Try the new Yahoo! Search -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Calculations
Hi Jerry, JeRRy said: Hi, I am not sure if this is possible or not or in what format etc. Maybe it's a PHP, mysql or even a JavaScript thing. But thought I'd post here and see if people are aware if it is possible for what I want to do. I have searched alot on the net and yet have not come accross what I am looking for, so posting here may get me pointed in the right direction. Okay here is what I wanna do. :) I have a list of users in multiple tables in the one database. Each user has a field named 'score'. As the table numbers go higher generally the score goes higher but never lower than the previous table. There are 22 tables named 1 to 22. So an example is below: First of all, why do you have 22 tables??? It would be much more efficient using only ONE. It would include the fields: 1) ID 2) user 3) score or something like that. MySQL can easily order them by score. SELECT user, score FROM your_table ORDER BY score MySQL can also get the total score. SELECT sum(score) FROM your_table So, I would call this a MySQL subject. Think over your database design. Regards, Sebastian -- Once a problem is defined - it is half way solved. (Henry Ford) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] calculations based on checkbox value
Ok here is my problem, currently I have a form that calculates the number of words in a given textarea. Now what I need to accomplish is using a checkbox to subtract a value based on said checkbox. I have looked for a tutorial on such an item and did not find one so I am asking if anyone out there has accomplished a similar function and if so could you point out a good tutorial or let me see some sample code? Thanks in advance, Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] calculations based on checkbox value
can you post some code, and an exmaple of an input, the current output, and what the desired output would be? -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: 22 March 2002 04:57 To: [EMAIL PROTECTED] Subject: [PHP-DB] calculations based on checkbox value Ok here is my problem, currently I have a form that calculates the number of words in a given textarea. Now what I need to accomplish is using a checkbox to subtract a value based on said checkbox. I have looked for a tutorial on such an item and did not find one so I am asking if anyone out there has accomplished a similar function and if so could you point out a good tutorial or let me see some sample code? Thanks in advance, Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.338 / Virus Database: 189 - Release Date: 14/03/02 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.338 / Virus Database: 189 - Release Date: 14/03/02 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php