473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

cannot sum specific variables

Hello all.
I have a form that users are able to enter dollar amounts for each month and add them to the table. i am having difficulty adding cells that display the totals. For example, rows have 12 columns(one for each month) I would like to have a 13th that totals the entire row. Also at the bottom of the table, i need to have a total for only that column. I hope this makes sense. Below is the code for one of the tables.

Expand|Select|Wrap|Line Numbers
  1. // income
  2.     $_SESSION["a$CDID"]['pl']['income']['0'] = '';
  3.     if (isset($_POST['iicomp']))
  4.     {
  5.         $mkey = $_POST['iicomp'];
  6.         $istate = $_POST['completed'];
  7.  
  8.     }
  9.     if (isset($_GET['idel']))
  10.         {
  11.         unset($_SESSION["a$CDID"]['pl']['income'][$_GET['idel']]);
  12.         foreach ($_SESSION["a$CDID"]['pl']['income'] as $line)
  13.             $tmp[] = $line;
  14.         $_SESSION["a$CDID"]['pl']['income'] = $tmp;
  15.         }
  16.     if (isset($_POST['income']))
  17.     {
  18.         if (!empty($_POST['key']))
  19.             $_SESSION["a$CDID"]['pl']['income'][$_POST['key']] = $_POST['income'];
  20.         else
  21.             $_SESSION["a$CDID"]['pl']['income'][] = $_POST['income'];
  22.     }
  23.     if (count($_SESSION["a$CDID"]['pl']['income']) > '1')
  24.     {
  25.         foreach ($_SESSION["a$CDID"]['pl']['income'] as $key => $val)
  26.         {
  27.                 if ($key != '0')
  28.                     $PRINT_INCOME .= '
  29.                     <tr class="input" '.$istyle.'><td>'.$key.'. '.$val['descript'].'</td><td>'.$val['jan'].'</td><td>'.$val['feb'].'</td>
  30.                     <td>'.$val['mar'].'</td><td>'.$val['apr'].'</td><td>'.$val['may'].'</td><td>'.$val['jun'].'</td><td>'.$val['jul'].'</td><td>'.$val['aug'].'</td><td>'.$val['sep'].'</td><td>'.$val['oct'].'</td><td>'.$val['nov'].'</td><td>'.$val['dec'].'</td>
  31. <td>"this is where I have been trying to insert a Sum for the row"</td>                    
  32. <td align="center"><a href="pl.php?cdid='.$CDID.'&iedit='.$key.'"><input type="image" src="icon-blue-check.gif"</a></td><td><a href="pl.php?cdid='.$CDID.'&idel='.$key.'"><input type="image" src="icon-red-minus.gif"</a></td></tr>';
  33.         }
  34.     }
  35.     else
  36.         $PRINT_INCOME = '<tr class="row"><td></td></tr>';
  37.     if (isset($_GET['iedit']))
  38.  
The code for displaying the row is
Expand|Select|Wrap|Line Numbers
  1. <?PHP if (isset($PRINT_INCOME)) echo $PRINT_INCOME; ?>
  2.  

Thankyou
May 1 '08 #1
1 1193
aktar
105 100+
Hi Subey,

I didn't quite understand the need for certain variables, but I've simplified your script:


[PHP]
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<?php

$CDID = 1;
$account = "a{$CDID}";


$_SESSION[$account]['pl'] = @$_POST['income'];

$total = 0;


for($i=0; $i<12; $i++){

$value = NULL;

if (isset($_POST['income'][$i])) $value = $_POST['income'][$i];

print "<td><input type='text' name='income[]' value='$value' style='width:50px; border:none; background-color:yellow;' /></td>";

$total = $total + $value;
}

print "<td>$total</td>";

?>
</tr>
</table>

<input type="submit" name="button" id="button" value="Total up" />
[/PHP]

Ps the yellow boxes are form fields

Regards
May 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
5
by: Nathan Sokalski | last post by:
When running a page I am working on, I recieve the following error: Cannot use a leading .. to exit above the top directory. I suspect this has something to do with the problem I posted in a...
7
by: Brian Kitt | last post by:
I frequently get the above error on my website. It happens only for short periods of times, then the error goes away. I cannot recreate this. I have an error trap that picks up this error. When...
10
by: ksrajalakshmi | last post by:
Hai , in a textbox am having text as "(20/100)+pay1*pay2" .it's a formula. and stored in a particular variable. string strformula="(20/100)+pay1*pay2" ; i've to substitute the value of the...
1
by: JustDucky | last post by:
Hi! I have a word template that utilizes a userform to gather information from the user and place it into specific Doc Variable locations within the form. If the user reopens the userform and...
2
by: leeperman | last post by:
In Dreaweaver I cannot filter my database results to display only specific data that is retrieved from mulptile drop down list on my search page. The drop down list selections are posted to my...
2
by: hayyal | last post by:
Hi Folks, Just wanted to know few things about static variables. why static variables cannot be accessed in other files by using extern in c/c++? whats the difference between global and...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
2
by: lunabelle22a | last post by:
Hi, I have 125 unique variables and corresponding values in a data file with 6 fixed-width columns (columns alternate between "variables" and "values"). If I only need 6 of these variables and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.