473,326 Members | 2,061 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,326 software developers and data experts.

calculate in PHP

hey guys, i was just wondering how to do calculations in php.

i have a table, currently in the table are firstname,surname, then there are lists of stores eg. Boots,woolworths,hospital etc

so the page loads with just the first name, then say 0.8 is entered into boots, 0.7 entered into woolworths, the user then submits the data, i would like the data to be entered into my database, but then also caqlculated into a total for the person and displayed on screen

example
firstname,surename,boots,woolworths,hospital, dr, other, total
bloggs, joe, 0.8 0.8 0.8 0.8 0.8 total of hours
bloggs2, joe, 0.8 0.8 0.8 0.8 0.8 total of all hours
bloggs4, joe, 0.8 0.8 0.8 0.8 0.8 total of hours
bloggs, joe, 0.8 0.8 0.8 0.8 0.8 total of hours

so the total column is populated after submit s pressed for each row.

hope i have explained clearly enough.
Apr 9 '07 #1
16 3591
Motoma
3,237 Expert 2GB
PHP: Arithmetic Operators
Apr 10 '07 #2
PHP: Arithmetic Operators

im still lost on the idea
Apr 10 '07 #3
code green
1,726 Expert 1GB
What do you not understand about arithmetic operators?
Apr 10 '07 #4
What do you not understand about arithmetic operators?

how to go about doing it in PHP, if i understood it, i wouldnt not be on here asking for help.
Apr 11 '07 #5
tolkienarda
316 100+
hey guys, i was just wondering how to do calculations in php.

i have a table, currently in the table are firstname,surname, then there are lists of stores eg. Boots,woolworths,hospital etc

so the page loads with just the first name, then say 0.8 is entered into boots, 0.7 entered into woolworths, the user then submits the data, i would like the data to be entered into my database, but then also caqlculated into a total for the person and displayed on screen

example
firstname,surename,boots,woolworths,hospital, dr, other, total
bloggs, joe, 0.8 0.8 0.8 0.8 0.8 total of hours
bloggs2, joe, 0.8 0.8 0.8 0.8 0.8 total of all hours
bloggs4, joe, 0.8 0.8 0.8 0.8 0.8 total of hours
bloggs, joe, 0.8 0.8 0.8 0.8 0.8 total of hours

so the total column is populated after submit s pressed for each row.

hope i have explained clearly enough.
ok if all of the values for each person are in an array.
with the values being as follows
$person1[0] = bloggs;
$person1[1] = joe;
$person1[2] = 0.8;
$person1[3] = 0.8;
$person1[4] = 0.8;
$person1[5] = 0.8;
$person1[6] = 0.8;

$total = $person1[2] + $person1[3] $person1[4] + $person1[5] + $person1[6];

from your question i think this is what you wanted to do now; You would probably want to put that into a loop and do some error checking to make sure numbers were put in; Maybe even use a 2D array for holding multiple people, but that is basicaly how you add;

eric
Apr 11 '07 #6
ok if all of the values for each person are in an array.
with the values being as follows
$person1[0] = bloggs;
$person1[1] = joe;
$person1[2] = 0.8;
$person1[3] = 0.8;
$person1[4] = 0.8;
$person1[5] = 0.8;
$person1[6] = 0.8;

$total = $person1[2] + $person1[3] $person1[4] + $person1[5] + $person1[6];

from your question i think this is what you wanted to do now; You would probably want to put that into a loop and do some error checking to make sure numbers were put in; Maybe even use a 2D array for holding multiple people, but that is basicaly how you add;

eric
so how would i go bout doing that in code?
Apr 12 '07 #7
code green
1,726 Expert 1GB
Make an attempt!
Apr 12 '07 #8
Make an attempt!
nice reply thanks, but do u not think that if i hadnt tried already i would be back on here.
Apr 12 '07 #9
Motoma
3,237 Expert 2GB
nice reply thanks, but do u not think that if i hadnt tried already i would be back on here.
If you want some help, READ THE POSTING GUIDELINES. You will see that we are not code-monkeys; we are here to help correct problems with your code.
You have not posted any code, and this makes it hard for us to debug it.
Apr 12 '07 #10
If you want some help, READ THE POSTING GUIDELINES. You will see that we are not code-monkeys; we are here to help correct problems with your code.
You have not posted any code, and this makes it hard for us to debug it.
[php]

<?php
/*
create table users (id int, staffid int, region varchar(20), firstname varchar(20), surname varchar(20));
insert into users values(1,1,'region1','John', 'Doe'),(2,2,'region1','Pete', 'Mackay');
create table stores (name varchar(10));
insert into stores values('Name1'),('Name2'),('Name3'),('Name4'),('Na me5'),('Name6');
*/
$con = mysql_connect("localhost","root","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);

$sql="SELECT firstname, surname, boots, dc, hos, br, hv, other, ppp, days FROM users WHERE region='DO' order by firstname ASC";
$result=mysql_query($sql)
or die("Error Occured while Searching Records : " . mysql_error());

//$sq1="SELECT * FROM regional_deployment WHERE firstname='dave'";
//$result=mysql_query($sql)
//or die("Error Occured while Searching Records : " . mysql_error());

echo "<table border='1' align='center'>
<tr>

<th>Firstname</th>
<th>Surname</th>
<th>Boots</th>
<th>DC</th>
<th>Hos</th>
<th>Br</th>
<th>HV</th>
<th>Other</th>
<th>PPP</th>
<th>Days</th>

</tr>";

while($row = mysql_fetch_assoc($result)) {
echo "<tr>";

echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['boots'] . "</td>";
echo "<td>" . $row['dc'] . "</td>";
echo "<td>" . $row['hos'] . "</td>";
echo "<td>" . $row['br'] . "</td>";
echo "<td>" . $row['hv'] . "</td>";
echo "<td>" . $row['other'] . "</td>";
echo "<td>" . $row['ppp'] . "</td>";
echo "<td>" . $row['days'] . "</td>";





}
echo "</table>";mysql_close($con);


?>
</div>
<div align="center">
<div align="center"><br>
<br>
<br>
<br>
<br>
<input name="clickback2" type="button" value="Back" onClick="history.go(-1)">
<input name="submit" type='submit' value='Submit' />
</div>
<div align="center"> </div>
<div align="center">

</div>

[/PHP]


SO THAT CODE MAKES A TABLE, the table will have text boxes under neath the names of different stores, the regional manager would come onto the page, then enter the hours worked at each place for each person, then press submit, the page would then be entered into a database, but then be displayed on the page with the total column filled from the values given in the fileds under the places.

lol i ham no good at explaining situations.

but hopefuly this will mean you can help me.
Apr 12 '07 #11
Motoma
3,237 Expert 2GB
Now we are getting somewhere.
I am going from the assumption that your code, right now, displays a table will all the employee data.

You will create a form page. Form page will query all of the employees, and list them in a TABLE. The TABLE will be inside a FORM. The table will have TH elements with the column/row titles. It will have columns/rows with the employee names and numbers, as well as an INPUT for each employee. At the end of the TABLE, but inside the FORM, you will have a submit INPUT. The form will POST to your handler page.

Your handler page will accept the POST, and iterate through it's values, first validating the data, then building a MySQL INSERT statement for each employee, and finally executing the INSERT query.
Apr 12 '07 #12
Now we are getting somewhere.
I am going from the assumption that your code, right now, displays a table will all the employee data.

You will create a form page. Form page will query all of the employees, and list them in a TABLE. The TABLE will be inside a FORM. The table will have TH elements with the column/row titles. It will have columns/rows with the employee names and numbers, as well as an INPUT for each employee. At the end of the TABLE, but inside the FORM, you will have a submit INPUT. The form will POST to your handler page.

Your handler page will accept the POST, and iterate through it's values, first validating the data, then building a MySQL INSERT statement for each employee, and finally executing the INSERT query.
opz sorry, that lost me.


currenty its a php form, that selects so far just the firstname and the surname, but also on the form, there are a few more colum headings as you can see in the code above na,med BOOTS,DOHC,HOSI,BR,PPP,OTHER, they have just got text boxes, ready for the regional manager to enter some hours in.

so they enter the hours for each person in the relavent textboxs, then i want for them to press the submit data, the data will then by inserted into the a database table i have created,.

but also will calculate the hours for each your and in the total column put the total for each person , then display the table on screen with the totals showing.

im just not to clear at explaining thinks and i know that makes it harder for you lot.

so the basics are

RM enters hours for each person, presses subit, hours are calculated while the submit is pressed,data entere dinto the database,then displayed on the screen with total hours for each.
Apr 12 '07 #13
Motoma
3,237 Expert 2GB
I guess what I am having trouble understanding, is what part of that isn't happening?
Apr 12 '07 #14
I guess what I am having trouble understanding, is what part of that isn't happening?

the calculation part, i dont know how to do calculations using php.

dont know i if could do $textbox1 + $textbox2 + $textbox 3 = $total and were to start doing calculations within dat code i showed.
Apr 12 '07 #15
code green
1,726 Expert 1GB
dont know i if could do
Expand|Select|Wrap|Line Numbers
  1. $textbox1 + $textbox2 + $textbox 3 = $total 
[PHP]$total = $textbox1 + $textbox2 + $textbox 3;[/PHP]

Expand|Select|Wrap|Line Numbers
  1. and were to start doing 
But you are no where near requiring the calculations yet.

the table will have text boxes under neath the names of different stores
But they haven't yet.
the page would then be entered into a database,
where?
but then be displayed on the page with the total column filled from the values given in the fileds under the places
You asked how to do calculations which are very simple, but the truth is you don't know how to post a page or enter data into a database or even create textboxes. That is why your problem is taking so long to solve. Forget about the poxy calculations and concentrate on designing your web page/database/php integration
Apr 13 '07 #16
Motoma
3,237 Expert 2GB
I would suggest doing a Google search on "PHP form submission tutorial." This will give you a good knowledge base on what you can and cannot do in PHP.
Apr 13 '07 #17

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

Similar topics

2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
1
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
2
by: Gálos Zsuzsa | last post by:
Hi all, I need to calculate Formulas. For example: dim strFormula as string="25*(12-6)" I ned a DotNet Function to calculate this Formula (25*(12-6)=150): dim dblValue as double = 150
1
by: Robert de Ridder | last post by:
I use an asp page to display pages, where the dynamic content is in an iframe. To calculate the height of the iframe I use the calcheight function. However when trying to do this with external...
4
by: Jan Szymczuk | last post by:
I'm creating an MS Access 2000 database where I have a number of people entered using simple basic fields, Surname: SMITH Forenames: John DoB: 09/09/1958 Age:...
1
by: Ladislau S. | last post by:
Dear reader, I am an occasional user of MS Access 2000 running on Windows 98. My hobby is ship model building so I made a database for things that I want to buy. After two strokes I bin unable...
6
by: charliewest | last post by:
Can someone pls point me to or recommend the easiest way to calculate someone´s age using the TimeSpan object, in .NET CF? Isn´t there a simple way to use the TimeSpan object to calculate the...
3
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
6
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.