i have a web page that displays some data from the database.
In my SQL table there are 4 users , for each of them there are two values of the current salary and the new salary
now when i select a user using the select field the data of the salaries is being presented.
I wanted to add another field that will add the current salary to the new salary so I added a line as follows :
echo "<td>" . $row['salary_cur'] + $row['salary_new'] ."</td>";
but in fact , i'm able to see only the value of ['salary_new'] so no calculation was effected.
Please help me to change this line so i will be able to see the result.
(i forgot to tell that i;m using Ajax here so the request is being sent from the html through a java script and then to the php. Maybe I'm not able to do calculations since Ajax is involved ? )
calculate two fields
Moderator: General Moderators
Re: calculate two fields
I think you should use ( ) surrounding .
Also, you could calculate it at DB layer:
Code: Select all
$row['salary_cur'] + $row['salary_new']Also, you could calculate it at DB layer:
Code: Select all
select salary_cur, salary_new, salary_cur + salary_new as salary_total ...
There are 10 types of people in this world, those who understand binary and those who don't
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: calculate two fields
You should actually do this in the query, where it belongs, not in the application.
Re: calculate two fields
Or you could do the arithmetic in the PHP, before echoing it back to the Ajax function as a separate value.
Code: Select all
$totsalary = $row['salary_cur'] + $row['salary_new'];
echo "<td>$totsalary</td>";