tags:

views:

130

answers:

2

I currently have a query

$query = "SELECT * FROM routes ORDER BY id DESC LIMIT 8;";

And that works all wonderfully.

I have table columns

id      int(10)        
name    varchar(45)   
base    varchar(16)   
econ    int(6)     
location    varchar(12)  
x   int(2)     
y   int(2)     
galaxy  int(2)     
planet  int(2)     
comment     varchar(100)   
ipaddress   varchar(45)

and on the page when this segment of php is called i will have the econ,X,Y,Galaxy,and planet of another entry

then i want to display the entry is the database(like i do at the moment) BUT i want a new column to be displayed that is not in the DB, this new column is to be the output of a calculation.. the calculation is to be

Sqrt(min. Economy) x ( 1 + Sqrt(Distance)/75 + Sqrt(Players)/10 )
Sqrt(88) x ( 1 + Sqrt(23)/75 + Sqrt(23)/10 ) = 15 cred./h

players is another variable that is already availible in my page

Distance is a function of the 2 galaxys unless there the same when its a function of the 2 x's and y's unless there the same and then its a funtion of the 2 planet intergers

here is the page i talk of..i will add a new button to compare.. thats the new function that i want to compare the given value with existing values. http://www.teamdelta.byethost12.com/trade/postroute2.php

A: 

After the query you store the results into an array. You could parse the array adding an item containing the calculation that you wrote. If you want more details you should past here the array

--
dam

dam
+2  A: 

You can just calculate in your query like this:

$query = "SELECT (Sqrt(min. Economy) x ( 1 + Sqrt(Distance)/75 + Sqrt(Players)/10 )    Sqrt(88) x ( 1 + Sqrt(23)/75 + Sqrt(23)/10 ) = 15 cred./h) as `Distance`, * FROM routes ORDER BY id DESC LIMIT 8;";

Use as for naming your calculation so its become a column and use * to get the other fields.

Corbifex
cool can i use sqrtand min in a query?
Arthur