rustybuddy — 2010-10-19T10:10:27-04:00 — #1
Have a situation where I need to show a US and Metric measurement on a web page. The spec in the database is in metric (meters). Of course I can use an equation in php to convert the units but it would be much better (I think?) to go ahead and convert the units in the mysql query.
I have a very VERY basic understanding of math in queries.
Maybe I can convert the meters to inches in the query and use php on the page to convert from inches to inches/feet or should I do it all in one swoop in the query?
Any guidance or push in the right direction would be very helpful.
This is being done with products specs so sometimes there will only be one product being queried and sometimes there will be a large list of them (50 max prolly) was thinking it would be easier and more efficient to maintain the calculation code in the query rather than having a php function.
Also this conversion method will be used to convert liters to gallons, cm's to inches...etc The products spec lists have between 10 -15 specs that will all need to be converted on the fly.
Thanks in advance for any guidance or assistance you may be able to provide.
r937 — 2010-10-19T10:15:44-04:00 — #2
i would do this in the front end application
you ~could~ do it in the query, but you will forever be futzing with the SQL
most installations (you know, where there are people like DBAs and Operations in charge of the production apps, and developers building new apps) will frown on repeated requests to tinker with the SQL
in my opinion it's better to have the database interface used strictly for retrieval, and then use the app language to present it whichever way is desired
same concept goes for date formatting, by the way
rustybuddy — 2010-10-19T17:01:45-04:00 — #3
Yup, figured that's where I would be heading. Thanks for the guidance. Built some nice conversion functions and have implemented them post-query to the records. Works very well and will be a breeze to maintain/modify (and also re-use) if I need the conversion anywhere else.
PHP was definitely the best place to make this happen.