Re: MySQL function in a Table's Column
| From: | Matt | Date: | Sat, 24 Nov 2001 23:54:49 +0000 |
| Subject: | Re: MySQL function in a Table's Column | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75625@lists.php.net to get a copy of this message | ||
> I basically want to make a column that will do math to other columns, like
in
> a spreadsheet program. Is it possible? And if so, what do I look for?
> And if you can give me an example that would be great.
No, you can't do that, you store the raw data, and do the math when you
retrieve it. It's bad database design to store summary data (i.e. a total
order amount vs calculating from detail lines), or data that can be derived
within a row itself by caclulating from other fields. The reasons are
basically that it wastes space in the db, and that the calculated values
become out of balance (and require cleanup programs/scripts to realign
them). Sometimes one must store this type of info for efficiency purposes,
and in those cases, the value is calculated (by you) and then stored in the
db; but it should be avoided as much as possible because of the db integrity
issue noted above.
In a spreadsheet it's different, right, the value isn't stored, it's
calculated when the sheet is modified. That's what you need to do. Retrieve
the row, calculate the value in the script, and display it. It looks to the
end-user like it was in the db, but only the basic info is there, such as
qty, and unit price. The extended price is calculated on demand as needed
from those two basic entities.