Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Field Calculations

phpMyEdit General     Field Calculations
Odoslať novú tému   Odpovedať na tému    
 
daejin     Založený: 13.05.2005   Príspevky: 3  
Príspevok Zaslal: 2005-05-13 05:23
Návrat hore  Odpovedať s citátom     

Hi folks, could anyone tell me how to do this properly? I looked through the forums for some examples and the documentation but it isn't clear. I tried the [sql] function to try and add up each row and come out with a with a calculation in the last field, but alas i have failed. Mysql comes back with a error not recognizing some of the basic calculations that can be done within itself. I run version 4.0.18. Can someone make a suggestion on another solution, in php or otherwise, that can do this?

Thanks in Advance.

 
ajh     Založený: 17.12.2003   Príspevky: 236  
Príspevok Zaslal: 2005-05-13 09:55
Návrat hore  Odpovedať s citátom     

It would help if you could post an example of what you are trying to do.

But in principle it works like this...

Let's say you have two columns in your table: F1 and F2 (both INTEGERs).

You would like to have a read-only field called "Sum" on your screen, so what you would define is something like...

Kód:
$opts['fdd']['Sum'] = array(
  'name'     => 'Sum',
  'select'   => 'T',
  'sql'      => 'SELECT F1 + F2 FROM PMEtable0'
);


Note that PME always aliases the table as PMEtable0.

 
daejin     Založený: 13.05.2005   Príspevky: 3  
Príspevok Zaslal: 2005-05-13 17:06
Návrat hore  Odpovedať s citátom     

Okay this is what ive been trying i have right now.

$opts['fdd']['sum'] = array(
'name' => 'sum',
'select' => 'N',
'sql' => 'SELECT quantity * price FROM PMEtable0'
);

As the last field in table, which corresponds to the sql field which is empty at the moment. quantity is the quantity of one field, numeric(bigint32) as well as price(bigint32).

The error i get is.

MySQL error 1064

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT quantity * price FROM PMEtable0 AS qf5 FROM forsale AS P** rest os cut off, then below that is the actual command

SELECT PMEtable0.id AS qf0,PMEtable0.Item AS qf1,PMEtable0.quantity AS qf2,PMEtable0.price AS qf3,PMEtable0.total AS qf4,SELECT quantity * price FROM PMEtable0 AS qf5 FROM forsale AS PMEtable0 ORDER BY PMEtable0.id LIMIT 0,-15.992 miliseconds

Am i forgetting something simple? or is SQL just spitting it back because it doesn't like something in how its setup?

Thanks

 
ajh     Založený: 17.12.2003   Príspevky: 236  
Príspevok Zaslal: 2005-05-14 16:07
Návrat hore  Odpovedať s citátom     

No - you have an error because of course I was talking rubbish!!! Sorry!

Your SQL line should read:
Kód:

'sql' => 'quantity * price'


 
daejin     Založený: 13.05.2005   Príspevky: 3  
Príspevok Zaslal: 2005-05-14 21:52
Návrat hore  Odpovedať s citátom     

thanks it worked like a charm. Not to keep buggin you but any easy way to add up the sums of all rows and make one final total? its not really important just wondering if its do-able.

 
ajh     Založený: 17.12.2003   Príspevky: 236  
Príspevok Zaslal: 2005-05-15 08:53
Návrat hore  Odpovedať s citátom     

As far as I'm aware, this isn't do-able unfortunately.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov