This topic is locked
[SOLVED]

 Automatically Calculate Field In Table

8/2/2010 9:17:21 AM
PHPRunner General questions
D
denspad author

Hi all,
I have a tables with two fields that are entered manually by the user 'Project Value £' and 'Project Profitability £'. I have a third field in the same title entitled 'Project Profitability %'. The value for this field should be obtained by the following calculation Project Value £ / Project Profitability £.
I would like this to happen automatically when the fields are entered or at least when the record is added to the database.
Please can someone point me in the right direct as to what I need to look at in order to resolve this problem.
Regards,
Den.

N
nitinjainDevClub member 8/2/2010



Hi all,
I have a tables with two fields that are entered manually by the user 'Project Value £' and 'Project Profitability £'. I have a third field in the same title entitled 'Project Profitability %'. The value for this field should be obtained by the following calculation Project Value £ / Project Profitability £.
I would like this to happen automatically when the fields are entered or at least when the record is added to the database.
Please can someone point me in the right direct as to what I need to look at in order to resolve this problem.
Regards,
Den.


Add the calculation code to the Before Record Added/Edited event.

S
swanside 8/2/2010



Add the calculation code to the Before Record Added/Edited event.


Have two of the fields in your table, so your table will look lie this

-- phpMyAdmin SQL Dump

-- version 3.2.5

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Aug 02, 2010 at 02:33 PM

-- Server version: 5.1.34

-- PHP Version: 5.2.9-2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;

/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;

/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;

/!40101 SET NAMES utf8 /;
--

-- Database: percent

--
-- --------------------------------------------------------
--

-- Table structure for table percent

--
CREATE TABLE IF NOT EXISTS percent (

ProjectValue£ varchar(10) NOT NULL,

ProjectProfitability£ varchar(10) DEFAULT NULL,

KEY ProjectValue£ (ProjectValue£)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--

-- Dumping data for table percent

--
INSERT INTO percent (ProjectValue£, ProjectProfitability£) VALUES

('100', '10');


In PHPRunner go to Edit SQL Query and use the sql like this.

SELECT

ProjectValue£,

ProjectProfitability£,

(select sum(ProjectValue£/ProjectProfitability£)) AS Profitability%

FROM percent


WHen you buile it, go to the add new, put in the ProjectValue£ and the ProjectProfitability£ and save it.

When you look at the list page it will show you Profitability%.
If you email me, I can send you the phprunner project for you to play with if it helps.

Paul.