This topic is locked

Help with calculated field

5/7/2008 2:53:14 PM
PHPRunner General questions
N
nelly author

Hello !
Am i being thick or just doin something wrong?
I Have created a fields that basically adds one field to another
The fields i have are
Price

Saloon

Estate
What i am doing is making the "saloon" field a custom field ad inserting the following code
$value = $data['price'] + 5;
The field displays the total which is fine but when i go to the SQl editor it shows as a null field
What am i doing wrong ?
Please help !!!!!

A
alang 5/7/2008

You are doing the right thing for display but if you want to write the value back to the database you will need to add some more code using SQL UPDATE command.

N
nelly author 5/7/2008

You are doing the right thing for display but if you want to write the value back to the database you will need to add some more code using SQL UPDATE command.


thanks.............how would i do this? im a novice!

J
Jane 5/8/2008

Hi,
to update records in the database execute UPDATE query in the database directly.

Here is a sample:

UPDATE TableName set Saloon=Price+5

N
nelly author 5/8/2008

Hi,

to update records in the database execute UPDATE query in the database directly.

Here is a sample:


Hello Jane
I have tried doing that and it comes back with an SQL syntax error
The table name is `_estimate`
SELECT

id,

collection,

destination,

price,

vehicle,

saloon,

estate,

mpv,

mpvplus,

eightseater

FROM `_estimate`
what I am trying to do is this:
I am trying to write the values of saloon, estate, mpv, mpvplus & eightseater back to the sql tables.
the code i have entered into the viewer are
$value = $data['price'] + 0;

$value = $data['price'] + 5; for the estate field

$value = $data['price'] + 15; for the mpv and so on
I am obviously doing something wrong because when i try to enter your method a syntax error is returned.
Do i use your method in the SQL editor ?
Please help !!!

J
Jane 5/8/2008

Execute UPDATE query in the database directly (use any MySQL administrative tool for that).

N
nelly author 5/8/2008

Execute UPDATE query in the database directly (use any MySQL administrative tool for that).


Hi again !
I have tried that and i still get the syntax error
this is what i have done
SELECT

id,

collection,

destination,

price,

vehicle,

saloon,

estate,

mpv,

mpvplus,

eightseater

FROM `_estimate`

UPDATE `_estimate` SET saloon=price+0
just comes up with syntax SQL error !!
is my syntax correct?
Sorry for being a complete moron !! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=28999&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />

J
Jane 5/8/2008

Here is the correct query:

UPDATE `_estimate` SET saloon=price+0



Also I recommend you to have a look at the following articles:

http://www.webcheatsheet.com/sql/interacti.../sql_update.php

http://www.w3schools.com/sql/sql_update.asp

N
nelly author 5/8/2008



Hi again !
I have tried that and i still get the syntax error
this is what i have done
SELECT

id,

collection,

destination,

price,

vehicle,

saloon,

estate,

mpv,

mpvplus,

eightseater

FROM `_estimate`

UPDATE `_estimate` SET saloon=price+0
just comes up with syntax SQL error !!
is my syntax correct?
Sorry for being a complete moron !! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=29005&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />


Ok it has worked now!!! sorry !! thanks !!!!
But my problem is now that when i adda new record it does not automatically do this i have to go back to the SQL editor and do it manually !
Should i use the "after record updated" command in the events panel if so what is the correct syntax to use?
I will love you for ever if you can show me the correct way !!!! promise!!!!!!

J
Jane 5/8/2008

Use Before record added/Before record updated events for this purpose.

Here is a sample:

$values["saloon"] = $data["price"]+5; //for the saloon field

N
nelly author 5/8/2008

Use Before record added/Before record updated events for this purpose.

Here is a sample:


Guess what............. It didnt work ! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=29008&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
I can now open up the program in the browser all tables show correctly but when i add a new record it says
Error 8

Undefined variable: data
OMG !!! anything else i can try ?

J
Jane 5/8/2008

Sorry for my fault.

Here is the correct code:

$values["saloon"] = $values["price"]+5; //for the saloon field

N
nelly author 5/8/2008

Sorry for my fault.

Here is the correct code:


You are a STAR!!!!!
Many many thanks !!!!
Think i will stick to stamp collecting !